time
localtime
struct tm * localtime ( const time_t * timer );
Parameters
Return ValueA pointer to a tm structure with the time information filled in.
This structure is statically allocated and shared by the functions gmtime and localtime. Each time either one of these functions is called the content of this structure is overwritten.
Example /* localtime example */
#include <stdio.h>
#include <time.h>
int main ()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "Current local time and date: %s", asctime (timeinfo) );
return 0;
}
Output:
Current local time and date: Sat May 20 17:36:17 2000 time_t
This type is returned by the time function and is used as parameter by some other functions of the <ctime> header.
struct tm type <ctime>
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
The meaning of each is:
Member Meaning Range tm_sec seconds after the minute 0-61* tm_min minutes after the hour 0-59 tm_hour hours since midnight 0-23 tm_mday day of the month 1-31 tm_mon months since January 0-11 tm_year years since 1900 tm_wday days since Sunday 0-6 tm_yday days since January 1 0-365 tm_isdst Daylight Saving Time flag The Daylight Saving Time flag (tm_isdst) is greater than zero if Daylight Saving Time is in effect, zero if Daylight Saving Time is not in effect, and less than zero if the information is not available.
* tm_sec is generally 0-59. Extra range to accommodate for leap seconds in certain systems.
struct tm * localtime ( const time_t * timer );
Convert time_t to tm as local time
Uses the time pointed by timer to fill a tm structure with the values that represent the corresponding local time.Parameters
Return ValueA pointer to a tm structure with the time information filled in.
This structure is statically allocated and shared by the functions gmtime and localtime. Each time either one of these functions is called the content of this structure is overwritten.
Example /* localtime example */
#include <stdio.h>
#include <time.h>
int main ()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "Current local time and date: %s", asctime (timeinfo) );
return 0;
}
Output:
Current local time and date: Sat May 20 17:36:17 2000 time_t
Time type
Type capable of representing times and support arithmetical operations.This type is returned by the time function and is used as parameter by some other functions of the <ctime> header.
struct tm type <ctime>
Time structure
Structure containing a calendar date and time broken down into its components.
The structure contains nine members of type int, which are (in any order):
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
The meaning of each is:
Member Meaning Range tm_sec seconds after the minute 0-61* tm_min minutes after the hour 0-59 tm_hour hours since midnight 0-23 tm_mday day of the month 1-31 tm_mon months since January 0-11 tm_year years since 1900 tm_wday days since Sunday 0-6 tm_yday days since January 1 0-365 tm_isdst Daylight Saving Time flag The Daylight Saving Time flag (tm_isdst) is greater than zero if Daylight Saving Time is in effect, zero if Daylight Saving Time is not in effect, and less than zero if the information is not available.
* tm_sec is generally 0-59. Extra range to accommodate for leap seconds in certain systems.

浙公网安备 33010602011771号