|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Sep 2003
Città: Milano
Messaggi: 4623
|
[C] le date??
come si gestiscono le date in C?? sto iniziando a smanettare con C, e voglio fare una specie di agenda che mi gestisce gli appelli universitari, ma come faccio a gestire le date??? grazie
__________________
Ho trattato con : lahiri, czame, RC, allXXX, dfruggeri, JMM, Paperone, xej, Pappez, iperfly, Red81, Playmake, ryan78, Rob66, XP2200, Peach1200, faberjack, Stewie82, supermario_bros, hft500, Axelscorpio, pipes lee, Piccolospazio, RohanKish, miki66, kabira85 |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Questo è un programma di esempio...le funzioni con _ davanti le puoi scrivere anche senza...
Codice:
/* TIMES.C illustrates various time and date functions including: * time _ftime ctime asctime * localtime gmtime mktime _tzset * _strtime _strdate strftime * * Also the global variable: * _tzname */ #include <time.h> #include <stdio.h> #include <sys/types.h> #include <sys/timeb.h> #include <string.h> void main() { char tmpbuf[128], ampm[] = "AM"; time_t ltime; struct _timeb tstruct; struct tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 }; /* Set time zone from TZ environment variable. If TZ is not set, * the operating system is queried to obtain the default value * for the variable. */ _tzset(); /* Display operating system-style date and time. */ _strtime( tmpbuf ); printf( "OS time:\t\t\t\t%s\n", tmpbuf ); _strdate( tmpbuf ); printf( "OS date:\t\t\t\t%s\n", tmpbuf ); /* Get UNIX-style time and display as number and string. */ time( <ime ); printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime ); printf( "UNIX time and date:\t\t\t%s", ctime( <ime ) ); /* Display UTC. */ gmt = gmtime( <ime ); printf( "Coordinated universal time:\t\t%s", asctime( gmt ) ); /* Convert to time structure and adjust for PM if necessary. */ today = localtime( <ime ); if( today->tm_hour > 12 ) { strcpy( ampm, "PM" ); today->tm_hour -= 12; } if( today->tm_hour == 0 ) /* Adjust if midnight hour. */ today->tm_hour = 12; /* Note how pointer addition is used to skip the first 11 * characters and printf is used to trim off terminating * characters. */ printf( "12-hour time:\t\t\t\t%.8s %s\n", asctime( today ) + 11, ampm ); /* Print additional time information. */ _ftime( &tstruct ); printf( "Plus milliseconds:\t\t\t%u\n", tstruct.millitm ); printf( "Zone difference in seconds from UTC:\t%u\n", tstruct.timezone ); printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] ); printf( "Daylight savings:\t\t\t%s\n", tstruct.dstflag ? "YES" : "NO" ); /* Make time for noon on Christmas, 1993. */ if( mktime( &xmas ) != (time_t)-1 ) printf( "Christmas\t\t\t\t%s\n", asctime( &xmas ) ); /* Use time structure to build a customized time string. */ today = localtime( <ime ); /* Use strftime to build a customized time string. */ strftime( tmpbuf, 128, "Today is %A, day %d of %B in the year %Y.\n", today ); printf( tmpbuf ); } |
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Sep 2003
Città: Milano
Messaggi: 4623
|
con tutta laa buona volontà...non ci capisco molto...
![]()
__________________
Ho trattato con : lahiri, czame, RC, allXXX, dfruggeri, JMM, Paperone, xej, Pappez, iperfly, Red81, Playmake, ryan78, Rob66, XP2200, Peach1200, faberjack, Stewie82, supermario_bros, hft500, Axelscorpio, pipes lee, Piccolospazio, RohanKish, miki66, kabira85 |
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Sep 2003
Città: Milano
Messaggi: 4623
|
e poi mi da: errore alla riga 20
C:\Documents and Settings\Administrator\Desktop\SenzaTitolo1.cpp aggregate `struct _timeb tstruct' has incomplete type and cannot be initialized
__________________
Ho trattato con : lahiri, czame, RC, allXXX, dfruggeri, JMM, Paperone, xej, Pappez, iperfly, Red81, Playmake, ryan78, Rob66, XP2200, Peach1200, faberjack, Stewie82, supermario_bros, hft500, Axelscorpio, pipes lee, Piccolospazio, RohanKish, miki66, kabira85 |
![]() |
![]() |
![]() |
#5 |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Togli gli underscore...
|
![]() |
![]() |
![]() |
#6 |
Senior Member
Iscritto dal: Sep 2003
Città: Milano
Messaggi: 4623
|
fatto, ma mi da sempre quell'errore, cmq mi spieghi un pochino il codice? non capisco priprio
__________________
Ho trattato con : lahiri, czame, RC, allXXX, dfruggeri, JMM, Paperone, xej, Pappez, iperfly, Red81, Playmake, ryan78, Rob66, XP2200, Peach1200, faberjack, Stewie82, supermario_bros, hft500, Axelscorpio, pipes lee, Piccolospazio, RohanKish, miki66, kabira85 |
![]() |
![]() |
![]() |
#7 | |
Senior Member
Iscritto dal: Sep 2002
Città: Celano (AQ) Segno_Zodiacale: Leone Ascendente: Cammello Segni_Particolari: Quello
Messaggi: 9571
|
Quote:
che compilatore usi?? |
|
![]() |
![]() |
![]() |
#8 |
Senior Member
Iscritto dal: Sep 2003
Città: Milano
Messaggi: 4623
|
devc++
__________________
Ho trattato con : lahiri, czame, RC, allXXX, dfruggeri, JMM, Paperone, xej, Pappez, iperfly, Red81, Playmake, ryan78, Rob66, XP2200, Peach1200, faberjack, Stewie82, supermario_bros, hft500, Axelscorpio, pipes lee, Piccolospazio, RohanKish, miki66, kabira85 |
![]() |
![]() |
![]() |
#9 |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
A me su Dev-C++ funziona benissimo senza alcuna modifica (a parte int main):
Codice:
/* TIMES.C illustrates various time and date functions including: * time _ftime ctime asctime * localtime gmtime mktime _tzset * _strtime _strdate strftime * * Also the global variable: * _tzname */ #include <time.h> #include <stdio.h> #include <sys/types.h> #include <sys/timeb.h> #include <string.h> int main() { char tmpbuf[128], ampm[] = "AM"; time_t ltime; struct _timeb tstruct; struct tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 }; /* Set time zone from TZ environment variable. If TZ is not set, * the operating system is queried to obtain the default value * for the variable. */ _tzset(); /* Display operating system-style date and time. */ _strtime( tmpbuf ); printf( "OS time:\t\t\t\t%s\n", tmpbuf ); _strdate( tmpbuf ); printf( "OS date:\t\t\t\t%s\n", tmpbuf ); /* Get UNIX-style time and display as number and string. */ time( <ime ); printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime ); printf( "UNIX time and date:\t\t\t%s", ctime( <ime ) ); /* Display UTC. */ gmt = gmtime( <ime ); printf( "Coordinated universal time:\t\t%s", asctime( gmt ) ); /* Convert to time structure and adjust for PM if necessary. */ today = localtime( <ime ); if( today->tm_hour > 12 ) { strcpy( ampm, "PM" ); today->tm_hour -= 12; } if( today->tm_hour == 0 ) /* Adjust if midnight hour. */ today->tm_hour = 12; /* Note how pointer addition is used to skip the first 11 * characters and printf is used to trim off terminating * characters. */ printf( "12-hour time:\t\t\t\t%.8s %s\n", asctime( today ) + 11, ampm ); /* Print additional time information. */ _ftime( &tstruct ); printf( "Plus milliseconds:\t\t\t%u\n", tstruct.millitm ); printf( "Zone difference in seconds from UTC:\t%u\n", tstruct.timezone ); printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] ); printf( "Daylight savings:\t\t\t%s\n", tstruct.dstflag ? "YES" : "NO" ); /* Make time for noon on Christmas, 1993. */ if( mktime( &xmas ) != (time_t)-1 ) printf( "Christmas\t\t\t\t%s\n", asctime( &xmas ) ); /* Use time structure to build a customized time string. */ today = localtime( <ime ); /* Use strftime to build a customized time string. */ strftime( tmpbuf, 128, "Today is %A, day %d of %B in the year %Y.\n", today ); printf( tmpbuf ); system("pause"); } |
![]() |
![]() |
![]() |
#10 |
Senior Member
Iscritto dal: Sep 2003
Città: Milano
Messaggi: 4623
|
puoi spiegarmi un po' il codice? (sono alle prime armi)
__________________
Ho trattato con : lahiri, czame, RC, allXXX, dfruggeri, JMM, Paperone, xej, Pappez, iperfly, Red81, Playmake, ryan78, Rob66, XP2200, Peach1200, faberjack, Stewie82, supermario_bros, hft500, Axelscorpio, pipes lee, Piccolospazio, RohanKish, miki66, kabira85 |
![]() |
![]() |
![]() |
#11 |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Come ti ho detto, non è che si possa spiegare molto... E' l'uso pari pari delle funzioni (come anche scritto nei commenti)...
Qui trovi l'help: http://msdn.microsoft.com/library/en...asp?frame=true |
![]() |
![]() |
![]() |
#12 | |
Senior Member
Iscritto dal: Sep 2002
Città: Celano (AQ) Segno_Zodiacale: Leone Ascendente: Cammello Segni_Particolari: Quello
Messaggi: 9571
|
Quote:
![]() |
|
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 03:15.