gmtime function(Convert to Greenwich Mean Time) in C Language – example and detail

In the C Programming Language, the gmtime function converts a calendar time (pointed to with the aid of timer) and returns a pointer to a structure containing a UTC (or Greenwich Mean Time) value.


The syntax for the gmtime function in the C Language is:

struct tm *gmtime(const time_t *timer);

Parameters or Arguments

timer A pointer to an object of kind time_t that carries a time value to convert.


The gmtime characteristic returns a pointer to a shape containing a UTC (Greenwich Mean Time) fee describing a nearby time pointed to by using timer.

Required Header

In the C Language, the required header for the gmtime function is:

#include <time.h>

Applies To

In the C Language, the gmtime function can be used in the following versions:

ANSI/ISO 9899-1990

gmtime Example

Let’s seem to be at an instance to see how you would use the gmtime function in a C program:

/* Example using gmtime by */

#include <stdio.h>
#include <time.h>

#define PDT (-7)

int main(int argc, const char * argv[])
    /* Define temporary variables */
    struct tm *gtime;
    time_t now;

    /* Read the current system time */

    /* Convert the system time to GMT (now UTC) */
    gtime = gmtime(&now);

    /* Display the time in PDT and UTC */
    printf ("Pacific Daylight Time: %2d:%02d\n", (gtime->tm_hour + PDT) % 24, gtime->tm_min);
    printf ("Universal Time:        %2d:%02d\n", gtime->tm_hour % 24, gtime->tm_min);

    return 0;

When compiled and run, this software will output the cutting-edge time in both the Pacific Daylight and Universal timezones. When we ran the application at 2:14PM, the output was the following:

Pacific Daylight Time: 14:14
Universal Time:        21:14

Similar Functions

Other C features that are similar to the gmtime function:

asctime feature ctime characteristic difftime feature localtime function mktime characteristic strftime characteristic time characteristic