gmtime

Description

Converts a time value to a structure.

#include <time.h>

struct tm *gmtime( const time_t *time );

timer Pointer to stored time  

Remarks

The gmtime function converts the timer value to a structure. The timer argument represents the seconds elapsed since midnight (00:00:00), December 31, 1899, Universal Coordinated Time. This value is usually obtained from a call to the time function.

The gmtime function breaks down the timer value and stores it in a structure of type tm, defined in TIME.H. The structure result reflects Universal Coordinated Time, not local time.

The fields of the structure type tm store the following values, each of which is an int:

Field Value Stored

tm_sec Seconds
tm_min Minutes
tm_hour Hours (0–24)
tm_mday Day of month (1–31)
tm_mon Month (0–11; January = 0)
tm_year Year (current year minus 1900)
tm_wday Day of week (0–6; Sunday = 0)
tm_yday Day of year (0–365; January 1 = 0)
tm_isdst Always 0 for gmtime

The gmtime, mktime, and localtime functions use a single statically allocated structure to hold the result. Each call to one of these routines destroys the result of any previous call.

If timer represents a date before midnight, December 31, 1899, gmtime returns NULL.

Return Value

The gmtime function returns a pointer to the structure result. There is no error return.

Compatibility

Standards:ANSI, UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

See Also

asctime, ctime, _ftime, localtime, time

Example

/* GMTIME.C: This program uses gmtime to convert a long-integer

* representation of Universal Coordinated Time to a structure named newtime,

* then uses asctime to convert this structure to an output string.

*/

#include <time.h>

#include <stdio.h>

void main( void )

{

struct tm *newtime;

long ltime;

time( &ltime );

/* Obtain Universal Coordinated Time: */

newtime = gmtime( &ltime );

printf( "Universal Coordinated Time is %s\n", asctime( newtime ) );

}

Output

Universal Coordinated Time is Wed Jun 16 16:37:53 1999