#include <iostream>
#include <chrono>
using namespace std;
using namespace std::chrono;
int main() {
tm midnightTM{};
//获取当前时间
auto now{ system_clock::now() };
//将time_point转换为time_t
time_t midnightT{ system_clock::to_time_t(now) };
//将time_t转换为用tm表示的本地时间,在linux上可使用localtime_r()函数
localtime_s(&midnightTM, &midnightT);
//将时间部分设置为0点0分0秒
midnightTM.tm_hour = 0;
midnightTM.tm_min = 0;
midnightTM.tm_sec = 0;
//from_time_t将time_t转换为time_point,mktime接收tm*作为参数并返回time_t
auto midnight{ system_clock::from_time_t(mktime(&midnightTM)) };
auto duration_from_midnight = now - midnight;
//强制转换为秒数,小于1秒的部分舍弃
auto seconds_from_midnight{ duration_cast<seconds>(duration_from_midnight).count() };
//将持续时间转换为小时、分钟和秒
hh_mm_ss hms{ duration_from_midnight };
cout << hms.hours() << ":" << hms.minutes() << ":" << hms.seconds() << endl;
}