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.
It is almost universally expected to be an integral value representing the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC. This is due to historical reasons, since it corresponds to a unix timestamp, but is widely implemented in C libraries across all platforms.
struct tm
<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):
| |
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 |
time_t rawtime;
struct tm * timeinfo;time ( &rawtime );
timeinfo = localtime ( &rawtime );
std::cout<<"today is "<<timeinfo->tm_wday<<std::endl;
//判断某一日是周几
timeinfo->tm_year = lexical_cast<int>(ymd[0]) - 1900;
timeinfo->tm_mon = lexical_cast<int>(ymd[1]) - 1;timeinfo->tm_mday = lexical_cast<int>(ymd[2]);
// call mktime: timeinfo->tm_wday will be set */
mktime ( timeinfo );
std::cout<<"that day is "<<timeinfo->tm_wday<<std::endl;