【发布时间】:2013-10-30 09:59:48
【问题描述】:
我无法将 python datetime64 对象转换为字符串。例如:
t = numpy.datetime64('2012-06-30T20:00:00.000000000-0400')
进入:
'2012.07.01' as a string. (note time difference)
我已经尝试将 datetime64 对象转换为 datetime long 然后转换为字符串,但我似乎收到此错误:
dt = t.astype(datetime.datetime) #1341100800000000000L
time.ctime(dt)
ValueError: unconvertible time
【问题讨论】:
-
stackoverflow.com/questions/13703720/… 对您的具体问题有帮助吗?
-
谢谢,解决方案是:import pandas as pd ts = pd.to_datetime(str(date)) d = ts.strftime('%Y.%m.%d')
-
还有更简单的方法,看看下面我的回答
标签: python date datetime numpy