获得时间秒数(从1970.01.01 00:00:00算起)

博客给出一段C++代码示例,包含头文件time.h和iostream,在main函数中使用struct tm结构体设置时间为2005.07.21 22:35:23,通过mktime函数处理后输出结果,以避免重复回答相关问题。

近来有不少人问这问题,所以写到这来,免得重复回答

#include <time.h>
#include <iostream>
using std::cout;

int main (int argc, char* argv[])
{
 struct tm* when = (struct tm*) malloc (sizeof (tm);

 when->tm_year = 105;//2005.07.21 22:35:23 year = cur year - 1900
 when->tm_mon = 7;
 when->tm_mday = 21;
 when->tm_hour =21;
 when->tm_min = 35;
 when->tm_sec = 23;

 t = mktime (when);
 cout << t << endl;
 return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值