目录
时间段
- 表示时间间隔,可以是秒,分钟,小时,微妙,毫秒,纳秒
#include <chrono>
- using nanoseconds = duration<long long, nano>; //纳秒
- using microseconds = duration<long long, micro>; //微妙
- using milliseconds = duration<long long, milli>; //毫秒
- using seconds = duration<long long>; //秒
- using minutes = duration<int, ratio<60>>; //分钟
- using hours = duration<int, ratio<3600>>; //小时
#include<chrono> #include<iostream> #include<thread> using namespace std; int main() { chrono::duration<long long, ratio<60>>dur; cout << "延时1秒钟" << endl; this_thread::sleep_for(chrono::seconds(1)); cout << "延时1秒钟" << endl; //直接使用文本重载的形式使用时间,没必要用类去构造函数 this_thread::sleep_for(1s); cout << "延时500毫秒" << endl; this_thread::sleep_for(500ms); /*cout << "延时1小时" << endl;*/ /*this_thread::sleep_for(1h);*/ chrono:: hours h(1); chrono::minutes m(1); cout <<( h - m).count() << endl; return 0; }
时钟
- system_clock : 获取时间点,需要转换为time_t才能显示出来