C Standard Library

C <time.h> - gmtime() Function



The C <time.h> gmtime() function converts the value pointed by timer into calendar time, expressed in UTC time (time at the GMT timezone). The returned value a pointer to a tm object filled with the values representing UTC time for timer on success, or null pointer otherwise.

Syntax

struct tm * gmtime (const time_t * timer);

Parameters

timer Specify pointer to a time_t object to convert.

Return Value

Returns a pointer to a tm object filled with the values representing UTC time for timer on success, or null pointer otherwise. The structure may be shared between localtime(), gmtime(), and ctime(), and may be overwritten on each invocation of any of these functions.

Example:

The example below shows the usage of gmtime() function.

#include <stdio.h>
#include <time.h>
 
int main (){
  time_t t = time(NULL);
  struct tm * timeinfo = gmtime(&t);

  //displaying the result 
  printf("Current UTC time & date: %s",
       asctime(timeinfo)); 
  
  return 0;
}

The output of the above code will be:

Current UTC time & date: Fri Apr 16 10:48:25 2021

❮ C <time.h> Library

5