2024-04-26 06:03:44 发布
网友
我使用的是python2.7。在
我有一个日期时间对象:
mytime = 2016-02-16 16:01:52.619388+00:00
我需要按以下格式将其转换为unicode:
我的方法是:
unicode_time = unicode(datetime.isoformat(mytime)).replace('+00:00', 'Z')
但是,我不喜欢调用.replace()方法,它让我觉得很不舒服。有更好的方法吗?(可能是datetime模块支持的)
您可以使用[:-6]来去除+00:00字符串,然后添加Z。在
[:-6]
+00:00
Z
import datetime as dt >>> unicode(dt.datetime.isoformat(mytime)[:-6] + 'Z') u'2016-02-16T16:01:52.619388Z'
您可以使用
[:-6]
来去除+00:00
字符串,然后添加Z
。在相关问题 更多 >
编程相关推荐