C Library Functions -gmtime()
Description
C Library Functionsstruct tm *gmtime(const time_t *timer)Usagetimerthe value to filltmStructure, expressed in Coordinated Universal Time (UTC), also known as Greenwich Mean Time (GMT).
Declaration
Below is the declaration of the gmtime() function.
struct tm *gmtime(const time_t *timer)
Parameter
- timeptr-- This is a pointer to a time_t value representing the calendar time.
Return Value
This function returns a pointer to a tm structure that contains the filled-in time information. Below are the details of the timeptr structure:
Example
struct tm {
int tm_sec; /*Seconds, range from 0 to 59*/
int tm_min; /*Minutes, range from 0 to 59*/
int tm_hour; /*Hours, range from 0 to 23*/
int tm_mday; /*Day of the month, range from 1 to 31*/
int tm_mon; /*Month, range from 0 to 11*/
int tm_year; /*Years since 1900*/
int tm_wday; /*Day of the week, range from 0 to 6*/
int tm_yday; /*Day of the year, range from 0 to 365*/
int tm_isdst; /*Daylight saving time*/
};
Example
The following example demonstrates the usage of the gmtime() function.
Example
#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:\n");
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);
}
Let us compile and run the above program, which will produce the following result:
当前的世界时钟: 伦敦:14:10 中国:21:10other extensions