6

Previously I used Howard Hinnant's "date.h" header library but I recently switched to C++20's std::chrono (which is basically an implementation of Howard's cool library) but I cannot get the timezone abbreviations to print in a normal way (e.g. EST for New York time). All I get is GMT-4 (currently we are in daylight savings time).

I am using MSVC with Visual Studio 2022 PRE and I read that Microsoft are not using the full IANA database but something called ICU that is already downloaded by Windows. Could this be the cause of the missing abbreviations?

Here is the code I am using:

auto tm = std::chrono::system_clock::now();
std::cout << std::format("{:%X %Z}", std::chrono::zoned_time("America/New_York", tm));

For me at 22:55:52 in Singapore it prints 10:55:52 GMT-4 rather than 10:55:52 EST which is what I want.

Does anyone know how to resolve this on Microsoft Visual Studio using standard C++20?

David A
  • 123
  • 5
  • Since you are in daylight savings time, wouldn't you want [EDT instead of EST](https://en.wikipedia.org/wiki/Eastern_Time_Zone)? – clcto Jul 26 '21 at 16:25
  • In your bug report to the VS team it might help if you include a link to this site which has a complete human readable summary of the IANA tz data for each version of the database: http://nodatime.github.io/tzvalidate/ – Howard Hinnant Jul 26 '21 at 16:31
  • @HowardHinnant are you saying that it is a confirmed bug in MSVC? If so, I will report it. I just want to be sure that I am not doing something wrong in my code before I make a report. – David A Jul 27 '21 at 10:34
  • @clcto yes likely it is EDT rather than EST. – David A Jul 27 '21 at 10:39
  • Your code looks fine to me. For me it just output: 10:03:23 EDT. – Howard Hinnant Jul 27 '21 at 14:03

0 Answers0