自己网站做虚拟币违法吗,化工厂网站建设,wordpress 中文seo,护肤品网站模板打印时间精确到毫秒好实现#xff0c;但是那种对用户可读性不好#xff0c;更适合开头记一次结尾记一次#xff0c;打印中间减出来的程序运行时间。
但是因为一些情况#xff0c;我开多线程开的不方便打印结束时间#xff0c;同事跟我说那你把开始时间打印一下#xff0…打印时间精确到毫秒好实现但是那种对用户可读性不好更适合开头记一次结尾记一次打印中间减出来的程序运行时间。
但是因为一些情况我开多线程开的不方便打印结束时间同事跟我说那你把开始时间打印一下结束他自己接受那边打印最好精确到毫秒。那就要考虑可读性。
试了好多最后选择用这个
#include chrono
#include ctime
#include iostreamtemplate typename Duration
void print_time(tm t, Duration fraction) {using namespace std::chrono;std::printf([%04u-%02u-%02u %02u:%02u:%02u.%03u]\n, t.tm_year 1900,t.tm_mon 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec,static_castunsigned(fraction / milliseconds(1)));// VS2013s library has a bug which may require you to replace// fraction / milliseconds(1) with// duration_castmilliseconds(fraction).count()
}int main() {using namespace std;using namespace std::chrono;system_clock::time_point now system_clock::now();system_clock::duration tp now.time_since_epoch();tp - duration_castseconds(tp);time_t tt system_clock::to_time_t(now);print_time(*gmtime(tt), tp);print_time(*localtime(tt), tp);
}具体原理我先放放等有空了再研究 https://www.coder.work/article/798794