#include <wchar.h>
|
wchar_t *
wctime (const time_t *clock); |
wchar_t *
wasctime (const struct tm *tm); |
The function wctime adjusts the time value for the current time zone in the same manner as localtime, and returns a pointer to a 26-wide character string of the form:
Thu Nov 24 18:22:48 1986\n\0
The function wasctime converts the broken down time in the structure tm pointed at, by *tm to the form shown in the example above.
External declarations as well as the tm structure definition are in the
#include <time.h> include file.
The tm structure includes at least the following fields:
int tm_sec; /* seconds (0 - 60) */ int tm_min; /* minutes (0 - 59) */ int tm_hour; /* hours (0 - 23) */ int tm_mday; /* day of month (1 - 31) */ int tm_mon; /* month of year (0 - 11) */ int tm_year; /* year - 1900 */ int tm_wday; /* day of week (Sunday = 0) */ int tm_yday; /* day of year (0 - 365) */ int tm_isdst; /* is summer time in effect? */ char *tm_zone; /* abbreviation of timezone name */ long tm_gmtoff; /* offset from UTC in seconds */ The field tm_isdst is non-zero if summer time is in effect. The field tm_gmtoff is the offset (in seconds) of the time represented from UTC, with positive values indicating east of the Prime Meridian.
|
//Example usage of wasctime and wctime: #include <time.h> #include <stdio.h> int main(){ time_t t; struct tm *timeptr; wchar_t* wasc_time; t = time (NULL); //Get current time in seconds from Epoc //Fill tm struct w.r.t localtime using localtime timeptr = localtime (&t); //Use this to convert it to a string indicating time w.r.t localtime wasc_time = wasctime (timeptr); wprintf (L"Time from wasctime w.r.t localtime : %s", wasc_time); wprintf(L"Time from wctime w.r.t localtime : %s0, wctime(&t) ); return 0; }
Output
Time from wasctime w.r.t localtime : Thu Jun 22 10:42:27 2007 Time from wctime w.r.t localtime : Thu Jun 22 10:42:27 2007
The C Standard provides no mechanism for a program to modify its current local timezone setting, and the POSIX -standard method is not reentrant. (However, thread-safe implementations are provided in the POSIX threaded environment.)
The tm_zone field of a returned tm structure points to a static array of characters, which will also be overwritten by any subsequent calls (as well as by subsequent call to tzset )
© 2005-2007 Nokia |