C++ 将日期时间字符串干净地转换为纪元
是否有 C/C++/STL/Boost clean 方法将日期时间字符串转换为纪元时间(以秒为单位)?
yyyy:mm:dd hh:mm:ss
Is there a C/C++/STL/Boost clean method to convert a date time string to epoch time (in seconds)?
yyyy:mm:dd hh:mm:ss
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅:日期/时间转换:字符串表示形式到 time_t
以及:< a href="http://archives.free.net.ph/message/20060504.123105.73e1c873.en.html#boost-users" rel="nofollow noreferrer">[Boost-users] [date_time] 那么为什么没有不是 to_time_t 辅助函数?
所以,显然这样的东西应该可以工作:
但我不认为它比 Rob的建议:使用
sscanf
将数据解析为struct tm
,然后调用mktime
。See: Date/time conversion: string representation to time_t
And: [Boost-users] [date_time] So how come there isn't a to_time_t helper func?
So, apparently something like this should work:
But I don't think it's much cleaner than Rob's suggestion: use
sscanf
to parse the data into astruct tm
and then callmktime
.在 Windows 平台上,如果不想使用 Boost,你可以这样做:
如果你更喜欢标准库,你可以使用 struct tm 和 mktime() 来完成相同的工作。
On Windows platform you can do something like this if don't want to use Boost:
If you prefer standard library, you can use struct tm and mktime() to do the same job.
http://www.boost.org/doc/libs/ 1_39_0/doc/html/date_time.html
应该做到这一点。
http://www.boost.org/doc/libs/1_39_0/doc/html/date_time.html
Should do the trick.