C++ 以毫秒为单位获取时间,单位为C++;17?

C++ 以毫秒为单位获取时间,单位为C++;17?,c++,time,c++17,chrono,milliseconds,C++,Time,C++17,Chrono,Milliseconds,在C++17中,如何使用boost或标准库获取当前时间(以毫秒为单位)?我尝试使用std::chrono: intmain() { const auto currentDateTime=std::chrono::system_clock::now(); const auto currentDateTimet=std::chrono::system_clock::to_time_t(currentDateTime); const auto currentDateTimeLocalTime=*std

在C++17中,如何使用boost或标准库获取当前时间(以毫秒为单位)?我尝试使用std::chrono:

intmain()
{
const auto currentDateTime=std::chrono::system_clock::now();
const auto currentDateTimet=std::chrono::system_clock::to_time_t(currentDateTime);
const auto currentDateTimeLocalTime=*std::gmtime(¤tDateTimet);
char currentDateTimeArrStr[100];
std::strftime(currentDateTimeArrStr,100,“%Y%m%d\u%H%m%S.%f”,¤tDateTimeLocalTime);

std::clog所以只需打印从时间点开始的毫秒数

const auto ms = std::chrono::time_point_cast<std::chrono::milliseconds>(currentDateTime).time_since_epoch().count() % 1000;
std::clog << std::put_time(&currentDateTimeLocalTime, "%Y%m%d_%H%M%S") 
    << "." << std::setfill('0') << std::setw(3) << ms << std::endl;
const auto ms=std::chrono::time\u point\u cast(currentDateTime).time\u自\u epoch()以来的时间。count()%1000;

谢谢,但我需要5位毫秒的精度。那不是毫秒:D,“精度”不是“分辨率”,为提高精度,请您的系统分销商为您提供更精确的时钟源。5位毫秒值,即
10000 ms
将等于10秒。如果您希望输出分辨率为10微秒,则只需将时间点转换为微秒,将结果除以10,得到模100感谢您将其转换为微秒和纳秒,我想这是我想要的,但例如,使用这个python脚本
datetime.utcnow().strftime(“%Y%m%d\uh%m%s.%f”)我得到的输出如:“代码> > 207722120159336883636719' <代码>,这是我在C++中想要的。但是C++中不支持代码> %f>代码。所以…我想你可以编写自己的 StfTime//Cord>实现。你需要一个输出,如 12:0234.32622。这当然意味着你需要在MICR中的时间。秒(小数点后6位-毫秒仅为小数点后3位)。