unix time 相关

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):
1
2
3
4
5
6
7
8
9
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;


The meaning of each is:
MemberMeaningRange
tm_secseconds after the minute0-61*
tm_minminutes after the hour0-59
tm_hourhours since midnight0-23
tm_mdayday of the month1-31
tm_monmonths since January0-11
tm_yearyears since 1900
tm_wdaydays since Sunday0-6
tm_ydaydays since January 10-365
tm_isdstDaylight 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.

type

time_t

<ctime>
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.


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;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值