localtime

De RAD Studio
Aller à : navigation, rechercher

Remonter à Time.h - Index


Header File

time.h

Category

Time and Date Routines

Prototype

struct tm *localtime(const time_t *timer);

Description

Converts date and time to a structure.

localtime accepts the address of a value returned by time and returns a pointer to the structure of type tm containing the time elements. It corrects for the time zone and possible daylight saving time.

The global long variable _timezone contains the difference in seconds between GMT and local standard time (in PST, _timezone is 8 x 60 x 60). The global variable _daylight is used to tell the RTL’s functions (mktime & localtime) whether they should take daylight saving time into account if it runs into a date that would normally fall into that category. It is set to 1 if the daylight savings time conversion should be applied. These values are set by tzset, not by the user program directly.

This is the tm structure declaration from the time.h header file:

struct tm {

int tm_sec;

int tm_min;

int tm_hour;

int tm_mday;

int tm_mon;

int tm_year;

int tm_wday;

int tm_yday;

int tm_isdst;

};

These quantities give the time on a 24-hour clock, day of month (1 to 31), month (0 to 11), weekday (Sunday equals 0), year - 1900, day of year (0 to 365), and a flag that is nonzero if the daylight saving time conversion should be applied.

Return Value

localtime returns a pointer to the structure containing the time elements. This structure is a static that is overwritten with each call.

Example



 #include <time.h>
 #include <stdio.h>
 int main(void)
 {
    time_t timer;
    struct tm *tblock;
    /* gets time of day */
    timer = time(NULL);
    /* converts date/time to a structure */
    tblock = localtime(&timer);
    printf("Local time is: %s", asctime(tblock));
    return 0;
 }



Portability



POSIX Win32 ANSI C ANSI C++

+

+

+

+