c++ 时间相关的类型

关于时间转换可以参考以下博客:

https://www.jianshu.com/p/80de04b41c31

https://www.cnblogs.com/qicosmos/p/3642712.html

https://blog.csdn.net/wizardtoh/article/details/81738682

https://blog.csdn.net/hou8389846/article/details/77962343

get_time put_time相关

https://blog.csdn.net/wangjieest/article/details/7761051

https://www.yiibai.com/cpp_standard_library/cpp_get_time.html

time_point 相关

https://www.xuebuyuan.com/716692.html?mobile=1

 

hdu 6491

时间间隔

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 153    Accepted Submission(s): 96


Problem Description
2019年1月1日,在云栖出现了可能是全世界最长的以秒为单位的倒计时装置:九亿多秒倒计时,直到2050年。

给出一个时间S,我们想知道S距离2050年1月1日0点0时0分多少秒。

因为答案可能很大,请输出答案模100的值。
 

 

Input
第一行一个正整数 T (1T100000) 表示数据组数。

对于每组数据,一行一个字符串表示时间。
时间格式为:YYYY-MM-DD HH:MM:SS,分别表示年、月、日、时,分、秒。

输入的时间保证都在2019年1月1日以后(包含当天)。
 

 

Output
对于每组数据输出一行一个整数表示答案。
 

 

Sample Input
1 2019-01-01 00:00:00
 

 

Sample Output
0
 
 
#include<bits/stdc++.h>
using namespace std;

int main()
{
    string s;
    stringstream ss;
    s = "2050-01-01 00:00:00";
    ss << s;
    tm beg ;
    ss >> get_time(&beg,"%Y-%m-%d");
    ss >> get_time(&beg,"%H:%M:%S");
    auto next_time = chrono::system_clock::from_time_t(time_t(mktime(&beg)));
    int n;
    cin>>n;
    while(n--)
    {
        tm ed;
        cin >> get_time(&ed,"%Y-%m-%d");
        cin >> get_time(&ed,"%H:%M:%S");
        auto from_time = chrono::system_clock::from_time_t(time_t(mktime(&ed)));
        auto diff = next_time - from_time ;
        cout<<abs(chrono::duration_cast<chrono::seconds>(diff).count())%100<<endl;
    }
    return 0;
}
View Code

 

posted @ 2019-04-24 22:23  hk_lin  阅读(204)  评论(0编辑  收藏  举报