# Include <time. h>
# Include <stdio. h>
Void main ()
{/* Method 1
Time_t curTime = time (NULL );
Char * curDate = ctime (& curTime );
Printf (curDate );
-----------------------
| Pass the NULL parameter to time () to obtain the current date and time
| Convert the obtained time and date to the C string type through ctime ()
| Output current time and date
*/
/* Method 2:
| Returns the current system date and time through time,
| Use localtime () to write the current date and time to the struct tm struct.
| Struct tm
| {
| Int tm_sec; // seconds after the minute-[0, 59]
| Int tm_min; // minutes after the hour-[0, 59]
| Int tm_hour; // hours since midnight-[0, 23]
| Int tm_mday; // day of the month-[1, 31]
| Int tm_mon; // months since January-[0, 11]
| Int tm_year; // years since 1900.
| Int tm_wday; // days since Sunday-[0, 6]
| Int tm_yday; // days since January 1-[0,365]
| Int tm_isdst; // daylight savings time flag
| };
| Specify the output format as year, month, day, hour, minute, and second
| Output the formatted date and time to the character array.
Time_t curTime = time (NULL );
Struct tm * localTime = localtime (& curTime );
Char s [50];
Char * format = "% y-% m-% d % H: % M: % S ";
Size_t max_size = 49;
Size_t result = strftime (s, max_size, format, localTime );
If (result! = 0)
Printf (s );
*/
/* Method 3
| Get the current system time through time ()
| Converts the system time to the local time
| Converts the local time to a string (using strftime () internally)
| The current system time and date represented by the output string
Time_t curTime = time (NULL );
Struct tm * localTime = localtime (& curTime );
Char * cTime = asctime (localTime );
Printf (cTime );
*/
Getchar ();
}