The Surprising Struggle with UTC Time Strings in C/C++
2025-01-19

This article delves into the complexities of converting UTC time strings to Unix timestamps in C/C++. The author uncovers unexpected behaviors in POSIX time handling functions across various C libraries and languages. The focus is on using `strptime()`, `mktime()`, and `timegm()`, highlighting issues with daylight saving time and locales. Solutions are provided, including using `timegm()` for UTC times and leveraging C++ streams to bypass locale problems. The article concludes by recommending more robust time handling libraries available in C++20 and later, such as Howard Hinnant's tz library.
Development