C library function - localtime()
Description
C Library Function **struct tm localtime(const time_t timer) Uses the value of timer to fill in the tm structure.timer The value of tm is broken down into a tm structure and expressed in the local time zone.
Declaration
Here is the declaration of the localtime() function.
struct tm *localtime(const time_t *timer)
Parameters
- timer -- This is a pointer to a time_t value representing calendar time.
Return Value
This function returns a pointer to tm a structure containing the filled-in time information. Here are the details of the tm structure:
struct
tm
{
int
tm_sec
;
/*
Seconds, ranging from 0 to 59
*/
int
tm_min
;
/*
Minutes, ranging from 0 to 59
*/
int
tm_hour
;
/*
Hours, ranging from 0 to 23
*/
int
tm_mday
;
/*
Day of the month, ranging from 1 to 31
*/
int
tm_mon
;
/*
Month, ranging from 0 to 11
*/
int
tm_year
;
/*
Years since 1900
*/
int
tm_wday
;
/*
Day of the week, ranging from 0 to 6
*/
int
tm_yday
;
/*
Day of the year, ranging from 0 to 365
*/
int
tm_isdst
;
/*
Daylight Saving Time
*/
}
;
Example
The following example demonstrates the use of the localtime() function.
Example
#include
<
stdio.h
#include
<
time.h
int
main
(
)
{
time_t
rawtime;
struct
tm
info
;
char
buffer
[
80
]
;
time
(
&
rawtime
)
;
info
=
localtime
(
&
rawtime
)
;
printf
(
"
Current local time and date: %s
"
,
asctime
(
info
)
)
;
return
(
0
)
;
}
Let's compile and run the above program, which will produce the following result:
当前的本地时间和日期:Thu Aug 23 09:12:05 2012
C Standard Library -