Home >>C Time Library Function >C gmtime() function

C gmtime() function

C gmtime() function

The C gmtime() function uses the value pointed by timer to fill a tm structure with the values that represent the corresponding time and expressed in Coordinated Universal Time (UTC) or GMT timezone rather than the local time.

Syntax:
struct tm *gmtime(const time_t *timer)

Parameter Values

timeptr- It is the pointer to a time_t value representing a calendar time.

Here is an example of 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:\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);
}

Output:
Current world clock:
London : 11:08
China : 18:08

No Sidebar ads