C library functions - gmtime ()
description
C library functionsstruct tm * gmtime (const time_t * timer) uses the value of the timertm structure to fill and use Coordinated Universal Time (UTC) is also known as Greenwich Mean Time (GMT) represented.
statement
The following is a statement gmtime () function.
struct tm *gmtime(const time_t *timer)
parameter
- timeptr - This is a pointer to a pointer showing a time_t calendar time value.
return value
This function returns a pointer to tm structure, the structure is filled with time information. Here are the details timeptr structure:
struct tm { int tm_sec; /* 秒,范围从 0 到 59 */ int tm_min; /* 分,范围从 0 到 59 */ int tm_hour; /* 小时,范围从 0 到 23 */ int tm_mday; /* 一月中的第几天,范围从 1 到 31 */ int tm_mon; /* 月份,范围从 0 到 11 */ int tm_year; /* 自 1900 起的年数 */ int tm_wday; /* 一周中的第几天,范围从 0 到 6 */ int tm_yday; /* 一年中的第几天,范围从 0 到 365 */ int tm_isdst; /* 夏令时 */ };
Examples
The following example demonstrates gmtime () function is used.
#include <stdio.h> #include <time.h> #define BST (+1) #define CCT (+8) int main () { time_t rawtime; struct tm *info; time(&rawtime); /* 获取 GMT 时间 */ info = gmtime(&rawtime ); printf("当前的世界时钟:\n"); printf("伦敦:%2d:%02d\n", (info->tm_hour+BST)%24, info->tm_min); printf("中国:%2d:%02d\n", (info->tm_hour+CCT)%24, info->tm_min); return(0); }
Let's compile and run the above program, which will result in the following:
当前的世界时钟: 伦敦:14:10 中国:21:10