且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

格式化 std::time 输出

更新时间:2022-11-30 14:07:46

(目前)有两种 now 方法:Instant::nowSystemTime::now.

There are (currently) two now methods: Instant::now and SystemTime::now.

Instant 说:

对单调递增时钟的测量.不透明且仅在 Duration 时有用.

A measurement of a monotonically increasing clock. Opaque and useful only with Duration.

SystemTime 说:

系统时钟的测量值,对于与文件系统或其他进程等外部实体进行通信非常有用.

A measurement of the system clock, useful for talking to external entities like the file system or other processes.

这些都不适合向人类展示.时间困难格式化时间是额外的复杂性.不属于标准库确实是一件好事,否则它就会有一个无法改进的固定API.

Neither of these is truly appropriate for showing to a human. Time is hard, and formatting time is additional complexity. It's really a good thing that it's not part of the standard library, otherwise it would have a fixed API that couldn't be improved.

如其他地方所述,我建议使用 chrono继承人time 箱子.

As mentioned elsewhere, I'd recommend using chrono, the heir apparent to the time crate.