In C programming the <time.h> gmtime function convert the calendar time in to a broken down time expressed as UTC(Coordinated Universal Time),which is essentially the Greenwich mean time.The declaration of the function is given below.
|struct tm *gmtime(const time_t *timer);|
timer -A time_t type variable that stores the calendar time.
struct tm -Returns a pointer to the broken-down time,or a null pointer if the specified time cannot be converted to UTC.
The calendar time here simply means the number of seconds elapsed since 1st January 1900,so the ‘timer’ holds the number of seconds and the ‘gmtime’ convert this seconds:numeric values,to UTC which can later be converted to the form,
Tue Jun 16 01:03:52 1973\n\0
by calling the function ‘asctime’ using the returned value as the argument.To get the number of seconds elapsed call the function ‘time’.A code example is given below.
struct tm *tt;
time(&t); //get the number of seconds elapsed since 1st January 1900
tt=gmtime(&t); //convert ‘t’ value to UTC
printf(“%s” , asctime(tt) ); //get the current UTC
Fri Jul 21 16:15:26 2017
The output time shown above may not be same as the time in your computer because the time given is the UTC,to get the local time you can call the ‘localtime’ or call the ‘ctime’ and pass ‘&t'(reference to ‘t’) as the argument.