mktime的使用
2016-02-28 22:45
459 查看
根据给定年月日计算出,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 + 1900 << "-" << 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; }
执行结果为:
相关文章推荐
- Android性能优化——优化下载以高效地访问网络
- ROS学习--轻松使用tf
- WPF中的DataGrid的RowDetail显示问题
- C语言字符串操作总结大全(超详细)
- 【MySQL】探究之TIMESTAMP
- linux内核分析第一周学习笔记
- 关于 adjustsFontSizeToFitWidth 的使用
- 第三次作业
- 分享在winform下实现左右布局多窗口界面-续篇
- 使用@Controller注解为什么要配置<mvc:annotation-driven />
- Linux下获取系统代理信息
- Nginx配置文件详解
- Kth Smallest Element in a BST
- Spiral Matrix
- 10. Regular Expression Matching-hard
- Password Validation using regular expressions(JavaScript)
- 数据包解析(基于wireshark)——物理层Frame
- PL/SQL之函数处理
- 字符集和编码
- 【CodeForces 520E】Pluses everywhere