English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C library function struct tm *gmtime(const time_t *timer) Using timer Fill the value tm The structure, and represented by Coordinated Universal Time (UTC), also known as Greenwich Mean Time (GMT).
Below is the declaration of the gmtime() function.
struct tm *gmtime(const time_t *timer)
This function returns a pointer to a tm structure that contains filled time information. Below are the details of the timeptr structure:
struct tm { int tm_sec; /* Second, ranging from 0 to 59 */ int tm_min; /* Minute, ranging from 0 to 59 */ int tm_hour; /* Hour, ranging from 0 to 23 */ int tm_mday; /* Day of the month, ranging from 1 to 31 */ int tm_mon; /* Month, ranging from 0 to 11 */ int tm_year; /* Since 19Years since 00 */ int tm_wday; /* Day of the week, ranging from 0 to 6 */ int tm_yday; /* Day of the year, ranging from 0 to 365 */ int tm_isdst; /* Daylight Saving Time */ };
The following example demonstrates the usage of the gmtime() function.
#include <stdio.h> #include <time.h> #define BST (+1) #define CCT (+8) int main () { time_t rawtime; struct tm *info; time(&rawtime); /* Get GMT time */ info = gmtime(&rawtime ); printf("Current world clock: "); printf("London: %2d:%02d\n", (info->tm_hour+BST)%24, info->tm_min); printf("China: %2d:%02d\n", (info->tm_hour+CCT)%24, info->tm_min); return(0); }
Vamos compilar e executar o programa acima, o que produzirá o seguinte resultado:
O relógio mundial atual: Londres:14:10 China:21:10