Functions can be used to obtain the current system in C ++.
Time_t time (time_t * timer );
If this function is used, if the input parameter is not null, it will set the current system time to this pointer.
The number returned by this function is from hours, Jan 1, 1970 UTC seconds.
struct tm * localtime (const time_t * timer);
Convert time_t type to local time
char* asctime (const struct tm * timeptr);
Format the local time into a string.
Example:
/* localtime example */#include <stdio.h> /* puts, printf */#include <time.h> /* time_t, struct tm, time, localtime */int main (){ time_t rawtime; struct tm * timeinfo; time (&rawtime); timeinfo = localtime (&rawtime); printf ("Current local time and date: %s", asctime(timeinfo)); return 0;}
Output:
Current local time and date: Wed Feb 13 17:17:11 2013 |
Of course, we can process the data in the structure of TM to obtain the output time in the desired format.