gmtime() Convert Time from Long Integer to Structure
#include <time.h>
struct tm *gmtime(time);
long *time; Pointer to stored time
gmtime() converts a time, stored as a long value, to a structure. The
long value 'time' represents the number of seconds that have elapsed
since 00:00:00, Jan 1 1970. (This value can be obtained from a call
to time()). The structure result reflects Greenwich mean time, not
local time.
The structure is of type 'tm', as defined in <time.h>. The fields of
structure 'tm' store the following values:
'tm_sec' Seconds
'tm_min' Minutes
'tm_hour' Hours (0-24)
'tm_mday' Day of month (1-31)
'tm_mon' Month (0-11; Jan = 0)
'tm_year' Year (current year minus 1900)
'tm_wday' Day of the week (0-6; Sun = 0)
'tm_yday' Day of the year (0-365; Jan 1 = 0)
'tm_isdst' Non-zero if daylight saving time, otherwise zero
Returns: A pointer to the structure result. There is no error
return.
Notes: gmtime() and localtime() use a single statically
allocated structure to hold the result. Each call to one
of these routines destroys the result of the previous
call.
DOS does not comprehend dates prior to its birth in 1980.
If 'time' represents a date prior to January 1, 1980,
gmtime() returns 00:00:00, January 1, 1980.
-------------------------------- Example ---------------------------------
The following statements get the time stored as a long integer, store
it in a structure, convert the structure to a character string, and
print it out.
#include <time.h>
#include <stdio.h>
long elapstime;
struct tm *greentime;
main()
{
time(&elapstime);
greentime = gmtime(&elapstime);
printf("Greenwich time is %s\n",asctime(greentime));
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster