Discussione: Trasformazione data
View Single Post
Old 24-03-2005, 07:38   #2
ilsensine
Senior Member
 
L'Avatar di ilsensine
 
Iscritto dal: Apr 2000
Cittā: Roma
Messaggi: 15625
Puoi usare le funzioni di time.h; ad esempio:
Codice:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <time.h>

int main(int argc, char **argv)
{
  struct tm t;
  time_t _t;
  if(argc!=2) {
    printf("Formato: %s <giorni>\n", argv[0]);
    return -1;
  }
  memset(&t, 0, sizeof(t));
  t.tm_year = 105; // 1900+105=2005
  t.tm_mday = atoi(argv[1]);
  _t = mktime(&t);
  t = *localtime(&_t);
  printf("%d giorni dall'inizio dell'anno: %s\n", atoi(argv[1]), asctime(&t));
  return 0;
}
La documentazione mi dice che mktime, localtime e asctime sono ISO9899, quindi dovrebbero essere disponibili su tutti i sistemi.
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al
andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12
ilsensine č offline   Rispondi citando il messaggio o parte di esso