我知道如何使用strptime
进行操作,但如何解释+0530
d = '2015-04-11 21:23:39+0530'
d = datetime.strptime(d,'%Y-%m-%d %H:%M:%S')
注意请不要建议关闭0530
。
答案 0 :(得分:0)
使用iso8601 lib
>>> import iso8601
>>> iso8601.parse_date('2015-04-11 21:23:39+0530')
datetime.datetime(2015, 4, 11, 21, 23, 39, tzinfo=<FixedOffset '+05:30' datetime.timedelta(0, 19800)>)
>>> type(iso8601.parse_date('2015-04-11 21:23:39+0530'))
<type 'datetime.datetime'>
答案 1 :(得分:0)
您可以使用dateutil
from dateutil import parser
d = '2015-04-11 21:23:39+0530'
p = parser.parse(d)
>>>p
datetime.datetime(2015, 4, 11, 21, 23, 39, tzinfo=tzoffset(None, 19800))
>>>p.date()
datetime.date(2015, 4, 11)
>>>p.time()
datetime.time(21, 23, 39)
>>>p.utcoffset()
datetime.timedelta(0, 19800) #seconds
>>>str(p.utcoffset())
'5:30:00' #UTC offset