• c++11之chrono类的时间使用


    时间点与时间段

    // system_clock example
    #include <iostream>
    #include <ctime>
    #include <ratio>
    #include <>
    
    using namespace std;
    using namespace std::chrono;
    
    int main()
    {
        using std::chrono::system_clock;
    
        std::chrono::duration<int> one_day(1);
    
        system_clock::time_point today = system_clock::now();
        system_clock::time_point tomorrow = today + one_day;
    
        std::time_t tt;
    
        tt = system_clock::to_time_t(today);
        
        // duration<long long, nano> nanoseconds;   //纳秒
        // duration<long long, micro> microseconds;   //微妙
        // duration<long long, milli> milliseconds;   //毫秒
        // duration<long long> seconds;
        // duration<int, ratio<60> > minutes;
        // duration<int, ratio<3600> > hours;
    
        std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(tomorrow- today);
        //std::cout << "time is: " << ms.count() << "
    ";
        std::cout << "time is: " <<today.time_since_epoch().count() << "
    "; //纳秒
        std::cout << "time is: " << std::chrono::duration_cast<std::chrono::milliseconds>(today.time_since_epoch()).count() << "
    ";  //毫秒
    
        //std::cout << "today is: " << ctime(&tt);
        std::cout << "today is: " << tt <<"
    ";
        tt = system_clock::to_time_t(tomorrow);
        //std::cout << "tomorrow will be: " << ctime(&tt);
        std::cout << "tomorrow will be: " << tt<<"
    ";
        return 0;
    }

     参考  C++11中的时间库std::chrono(引发关于时间的思考)_AlbertS Home of Technology-CSDN博客

  • 相关阅读:
    模拟测试48
    模拟测试47
    模拟测试46
    NOIP模拟测试29(A)
    NOIP模拟测试19
    NOIP模拟测试18(T3待更新)
    杂题
    noip模拟测试18 T2搜索
    noip模拟测试17 2019-08-11 考后反思
    noip模拟测试14 20190807 考试反思
  • 原文地址:https://www.cnblogs.com/lovebay/p/15002034.html
Copyright © 2020-2023  润新知