I have a string with the following format:
2010-11-04T23:23:01Z
The Z indicates that the time is UTC.
I would rather store this as a epoch time to make comparison easy.
What is the recomended method for doing this?
Currently (after a quck search) the simplist algorithm is:
1: <Convert string to struct_tm: by manually parsing string>
2: Use mktime() to convert struct_tm to epoch time.
// Problem here is that mktime uses local time not UTC time.
Best Answer
Using C++11 functionality we can now use streams to parse times:
The iomanip
std::get_time
will convert a string based on a set of format parameters and convert them into astruct tz
object.You can then use
std::mktime()
to convert this into an epoch value.