Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个类似于“2012-06-14 20:38:24.213-7:00”的字符串,并且想将其转换为 python 日期时间对象,时区保持不变,我该怎么做?
固定偏移量不足以找出时区名称。
否则pytz和/或dateutil库可能会有所帮助:
pytz
dateutil
>>> from dateutil import parser >>> parser.parse('2012-06-14 20:38:24.213-7:00') datetime.datetime(2012, 6, 14, 20, 38, 24, 213000, tzinfo=tzoffset(None, -25200))