I'm having troubles building a UTC date in c++ using the standard library. For example (any is fine):
- building from separate variables containing day month year...
or parsing
01/01/1970 00:00:00 UTC
01/01/1970 00:00:00 +0000
01/01/1970 00:00:00 # (implicitely in UTC)
Conditions:
- The timezone string does not need to be interpreted but I need to be sure the date is interpreted as UTC.
- the date is always correctly formated
- any formatting is accepted as long as it does the job
- should be portable (UNIX variants and Windows)
- avoid external libraries if possible
The best candidates so far are:
std::time_get
but specification doesn't say anything about the timezone (for what I understood of it :-) ).- boost's
date_time
, but its a pretty heavy dependency (mentioned in C++ library (unix) to parse date/time string Including timezones, but the answer predates C++11) - unix
strptime
is not portable on windows - messing around with
std::tm
directly, but on my system (glibc), it has non-standard undocumented fields (namely tm_zone ...). I suppose I could initialize it withgmtime(0)
then modify the days, month, year fields.
How can I build an std::chrono::time_point::time_point
from the UTC date?