简体   繁体   English

秒后的 system_clock::now() 值在 C++ 20 中代表什么?

[英]What does system_clock::now() value after seconds represent in C++ 20?

I'm exploring the timestamp in C++ 20 returned from system_clock::now() and when I print out the returned std::chrono::time_point it prints the date and time in the format YYYY-MM-DD HH:MM:SS.xxxxxxx .我正在探索从system_clock::now()返回的 C++ 20 中的时间戳,当我打印出返回的std::chrono::time_point时,它会以YYYY-MM-DD HH:MM:SS.xxxxxxx格式打印日期和时间YYYY-MM-DD HH:MM:SS.xxxxxxx

Any idea what the xxxxxxx value is?知道xxxxxxx值是什么吗? I assumed microseconds initially but I realised microseconds are to six decimal places whereas this value is always to seven.我最初假设是微秒,但我意识到微秒是小数点后六位,而这个值总是七。

I'm running this in VS 2022.我在 VS 2022 中运行它。

#include <iostream>
#include <chrono>

int main()
{
    using namespace std::chrono;
    auto timeDate = zoned_time{ current_zone(), system_clock::now() };
    std::cout << timeDate << std::endl;  // Output: 2022-07-29 08:55:22.8582577 BST
}

It's the fractional part of a second.这是一秒的小数部分。

The output you're getting comes from operator<<(zoned_time) .您得到的 output 来自operator<<(zoned_time) This outputs the time in the format "{:L%F %T %Z}" (see cppreference.com ).这会以"{:L%F %T %Z}"格式输出时间(参见cppreference.com )。 The %T part of the format is equivalent to "%H:%M:%S" ( reference ) and the %S specifies the seconds as a decimal floating-point number with a precision matching that of the precision of the input (ie the precision of system_clock::now() in your case).格式的%T部分等价于"%H:%M:%S"参考), %S将秒数指定为十进制浮点数,其精度与输入的精度相匹配(即在您的情况下system_clock::now()的精度)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM