Use these functions to get the current time and convert, adjust, and store it as necessary. The current time is the system time.
Data Structures | |
struct | _tm |
structure to store a date/time value. More... | |
Typedefs | |
typedef long | time_t |
Serial date/time. Holds number of seconds after January 1st, 1970. | |
typedef typedef__BEGIN_DECLS struct _tm | tm |
Type definition for struct _tm. | |
Functions | |
time_t | _mkgmtime (tm *timeptr) |
tm * | gmtime (CONST time_t *timer) |
Convert a time value to a structure. | |
int | gmtime_r (CONST time_t *timer, tm *ptm) |
Convert a time value to a structure. | |
tm * | localtime (CONST time_t *timer) |
Convert a time value and correct for the local time zone. | |
int | localtime_r (CONST time_t *timer, tm *ptm) |
Convert a time value and correct for the local time zone. | |
time_t | mktime (tm *timeptr) |
Convert the local time to a calendar value. | |
int | stime (time_t *timer) |
Set the system time. | |
time_t | time (time_t *timer) |
Get the system time. | |
Variables | |
u_char | _daylight |
Used to control daylight conversions. | |
long | _dstbias |
Difference between standard and daylight savings time in seconds. | |
long | _timezone |
Defines your local timezone. |
Convert a time value to a structure.
The gmtime function breaks down the timer value and stores it in a statically allocated structure of type tm, defined in time.h. The value of timer is usually obtained from a call to the time function.
timer | Pointer to stored time. The time is represented as seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC). |
Convert a time value to a structure.
Thread safe version of gmtime. See gmtime for more information.
timer | Pointer to stored time. The time is represented as seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC). | |
ptm | Pointer to structure tm where the converted time is stored. |
Convert a time value and correct for the local time zone.
The localtime function converts a time stored as a time_t value and stores the result in a structure of type tm. The long value timer represents the seconds elapsed since midnight (00:00:00), January 1, 1970, UTC. This value is usually obtained from the time function.
gmtime, mktime, and localtime all use a single statically allocated tm structure for the conversion. Each call to one of these routines destroys the result of the previous call.
localtime corrects for the local time zone if the user first sets the global variable _timezone.
timer | Pointer to stored time. |
Convert the local time to a calendar value.
The mktime function converts the supplied time structure (possibly incomplete) pointed to by timeptr into a fully defined structure with normalized values and then converts it to a time_t calendar time value. The converted time has the same encoding as the values returned by the time function. The original values of the tm_wday
and tm_yday
components of the timeptr structure are ignored, and the original values of the other components are not restricted to their normal ranges.
After an adjustment to Greenwich Mean Time (GMT), mktime handles dates from midnight, January 1, 1970, to January 19, 3:14:07, 2038. This adjustment may cause mktime to return -1 (cast to time_t) even though the date you specify is within range. For example, if you are in Cairo, Egypt, which is two hours ahead of GMT, two hours will first be subtracted from the date you specify in timeptr; this may now put your date out of range.
If successful, mktime sets the values of tm_wday
and tm_yday
as appropriate and sets the other components to represent the specified calendar time, but with their values forced to the normal ranges. The final value of tm_mday is not set until tm_mon and tm_year are determined. When specifying a tm structure time, set the tm_isdst
field to:
tm_isdst
is a required field. If not set, its value is undefined and the return value from mktime is unpredictable. If timeptr points to a tm structure returned by a previous call to gmtime or localtime, the tm_isdst
field contains the correct value.
timeptr | Pointer to time structure. |
int stime | ( | time_t * | timer | ) |
Set the system time.
timer | Pointer to the storage location for time. |
Get the system time.
The time function returns the number of seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC), according to the system clock. The return value is stored in the location given by timer. This parameter may be NULL, in which case the return value is not stored.
timer | Pointer to the storage location for time. |
Used to control daylight conversions.
Assign a nonzero value to enable daylight conversions. If enabled the hour part of time values is adjusted if we are in daylight saving time. Zero value to disable conversion. Default is enabled.
long _dstbias |
Difference between standard and daylight savings time in seconds.
This value is used to calculate the daylight savings time by subtracting this value from the standard time. Unit is seconds. Usually daylight savings time is one hour in advance to standard time, thus the default value is -1 * 60 * 60 = -3600.
long _timezone |
Defines your local timezone.
Difference in seconds between universal coordinated time and local time. This value is subtracted from the universal coordinated time to calculate your local time. Default value is 5 * 60 * 60 = 18000, which defines the time zone EST (GMT-5).