C++ Converting a time string to seconds from the epoch
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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: 2: Use mktime() to convert struct_tm to epoch time. // Problem here is that mktime uses local time not UTC time. 回答1: This is ISO8601 format. You can use strptime function to parse it with %FT%T%z argument. It is not a part of the C++ Standard though you can use open