什么是正确的格式字符串到分析的“ 04.05.2003 00:00:00.000” GMT; 0100 with strptime()?
我正在尝试将怪异格式的字符串时间戳转换为DateTime。这就是它的外观:
04.05.2003 00:00:00.000 GMT+0100
我正在尝试这样的事情,但它不匹配。我想我只是错过了GMT倒数的表达。
datetime.datetime.strptime('04.05.2003 00:00:00.000 GMT+0100','%d.%m.%Y HH:MM.SS.sss')
当然,它吐出了格式错误,
ValueError: time data '04.05.2003 00:00:00.000 GMT+0100' does not match format '%d.%m.%Y HH:MM.SS.sss'
我在这里需要使用什么格式字符串?
I am trying to convert a weird format string timestamp to a datetime. This is what it looks like:
04.05.2003 00:00:00.000 GMT+0100
I am trying something like this, but it's not matching. I think I am just missing the expression for that GMT offset at the end.
datetime.datetime.strptime('04.05.2003 00:00:00.000 GMT+0100','%d.%m.%Y HH:MM.SS.sss')
Of course it spits out the format error
ValueError: time data '04.05.2003 00:00:00.000 GMT+0100' does not match format '%d.%m.%Y HH:MM.SS.sss'
What is the format string I need to use here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
%z%z
与时区匹配。您正在使用一些奇怪的格式来匹配时间,%h:%m:%S。%f
应该适合此Use
%Z%z
to match the timezone. You were using some weird format for matching the time,%H:%M:%S.%f
should be appropriate for that您需要格式运算符,而不是
hh:mm:ss
,并且需要时区的格式运算符。时区偏移的运算符为%z
。You need format operators for the time, not
HH:MM:SS
, and you need a format operator for the timezone. The operator for a timezone offset is%z
.这应该有效:
This should work: