Function name : gmtime
Header file : <time.h>
Function prototype : struct tm *gmtime(long *clock);
Function : Used to convert the time in the clock to Greenwich Mean Time, and then return the result through the tm structure
Parameter: System time in long integer type
Return value : Returns a pointer to the structure tm, representing the current UTC time. The time returned by this function has not been time zone converted.
Supplement : The definition of tm structure is:
struct tm{
int tm_sec; //Represents the current number of seconds, the normal range is 0-59, but allows up to 61 seconds
int tm_min; //Represents the current score, range 0-59
int tm_hour; //Hour from midnight, range is 0-23
int tm_mday; //The number of days in the current month, range 01-31
int tm_mon; //Represents the current month, starting from January, ranging from 0-11
int tm_year; //The number of years since 1900, so +1900
int tm_wday; //The number of days in a week, starting from Monday, range is 0-6
int tm_yday; //The number of days since January 1 this year, the range is 0-365
int tm_isdst; //Daylight saving time, a positive number indicates that daylight saving time is implemented, 0 indicates that daylight saving time is not implemented, and a negative number indicates that the daylight saving time is not understood.
};
Program example : Convert system time t into structure tm, convert the structure into string, and output the result
#include<stdio.h>#include<time.h>intmain(void){time_tt;structtm*gmt,*area;t=time(NULL);area=localtime(&t);printf(Localtimeis:%s,asctime (area));gmt=gmtime(&t);printf(GMTis:%s,asctime(gmt));return0;}
Running results:
Localtimeis:TueJun1619:25:212020GMTis:TueJun1611:25:212020