Mainly used to obtain the display system time and timing, only to discuss the acquisition system time;
First on the code:
1#include"stdio.h"2#include"time.h"3 4 intMainvoid)5 {6 structTM *Local;7 time_t t;8t=Time (NULL);9Local=localtime (&t);Ten //Local=gmtime (&t); Oneprintf"%d.%d\n", local->tm_year+1900, local->tm_mon+1); A return 0; -}
Explain:
Use the time function to return a calendar period from January 1, 1970 0:0 0 seconds to the current number of seconds;
Use the LocalTime function to convert the calendar time to a TM structure to store it,
struct Definition I:
1 structTM2 {3 intTm_sec;/*seconds:0-59 (K&r says 0-61?)*/4 intTm_min;/*minutes:0-59*/5 intTm_hour;/*Hours since midnight:0-23*/6 intTm_mday;/*Day of the month:1-31*/7 intTm_mon;/*Months *since* january:0-11*/8 intTm_year;/*years since 1900*/9 intTm_wday;/*Days since Sunday (0-6)*/Ten intTm_yday;/*Days since Jan 1:0-365*/ One intTM_ISDST;/*+1 Daylight Savings time, 0 No DST, A *-1 don ' t know*/ -};
Call the corresponding member to display the system time;
The Time.h function in C language