Ciao ragazzi...
come faccio ad ottenere la data di sistema con il C++?
Ciao ragazzi...
come faccio ad ottenere la data di sistema con il C++?
Includi ctime e utilizza la funzione time per ottenere la data come numero di secondi passati dal 1900:
time_t rawtime;
time ( &rawtime );
per stampare la data puoi poi usare la funzione ctime:
printf ( "Current date and time are: %s", ctime (&rawtime) );
per avere le singole informazini giorno/mese/anno/ora minuti utilizza la funzioe gmtime per avere una struttura di tipo tm che contiene queste varie informazioni:
tm * ptm = gmtime ( &rawtime );
la struttura tm è cosi fatta:
typedef struct {
int tm_hour; /* hour (0 - 23) */
int tm_isdst; /* daylight saving time enabled/disabled */
int tm_mday; /* day of month (1 - 31) */
int tm_min; /* minutes (0 - 59) */
int tm_mon; /* month (0 - 11 : 0 = January) */
int tm_sec; /* seconds (0 - 59) */
int tm_wday; /* Day of week (0 - 6 : 0 = Sunday) */
int tm_yday; /* Day of year (0 - 365) */
int tm_year; /* Year less 1900 */
}
Sun Certified Java Programmer
EUCIP Core Level Certified
European Certification of Informatics Professionals
ma se io volessi stampare solo la variabile int tm_year; some devo fare???
time_t rawtime;
time ( &rawtime );
tm * ptm = gmtime ( &rawtime );
a questo punto l'anno lo trovi nella variabile ptm -> tm_year
Sun Certified Java Programmer
EUCIP Core Level Certified
European Certification of Informatics Professionals