To be portable, while I'm using the {fmt}
library for formatting dates and times, I encounter a small problem with printing times. Probably fmt
treats time as local time, whereas <iostream>
prints time as UTC?
Minimal example:
#include <chrono>
#include <fmt/chrono.h>
int main(){
using TimePoint = std::chrono::system_clock::time_point;
TimePoint localTime = std::chrono::system_clock::now();
auto localTimeStr = fmt::format("{:%F %T}", localTime);
std::cout << localTimeStr << std::endl
<< localTime;
return 0;
}
Output:
2023-03-15 21:47:46
2023-03-15 20:47:46.0631142
I'm using MSVC 19.34, fmt 9.1.0
How to set up fmt
to format time correctly in this case?
I read the documentation, but I don't see any solution. I expect to print the same value for the <iostream>
and fmt
strings.
How to format time to be printed in always in UTC using fmt lib?