欢迎光临
我们一直在努力

time.mktime(t),linux mktime

根据给定年月日计算出,1900-1-1到给定年月日的秒数,就可以使用mktime函数。

#include <iostream>#include <time.h>using std::cout;using std::endl;int main(){/* 获取1900-1-1距当前时间的秒数 */time_t now_seconds = time(0);struct tm cur_date;localtime_s(&cur_date, &now_seconds);cout << “seconds: ” << now_seconds << endl;cout << “date: ” << cur_date.tm_year + 190便宜香港vps0 << “-” << cur_date.tm_mon + 1 << “-” << cur_date.tm_mday << endl;/* 获取1900-1-1距离给定时间的秒数 */struct tm now_time;now_time.tm_year = 116;now_time.tm_yday = 58;now_time.tm_wday = 0;now_time.tm_sec = 0;now_time.tm_mon = 1;now_time.tm_min = 44;now_time.tm_mday = 28;now_time.tm_isdst = 0;now_time.tm_hour = 22;time_t sec = mktime(&now_time);cout << “result seconds: ” << sec << endl;}
执行结果为:

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。