如何从 np.datetime64 中提取小时/分钟/秒

Ach*_*113 4 python datetime numpy

我有一个日期时间对象,如下所示:

t = numpy.datetime64('2020-04-15T13:20:06.810000000') 我只想从中提取13:20:06. 我怎样才能做到这一点?

关于我发现的类似问题的所有答案都建议使用t.hourt.minute。但是当我尝试这样做时,我得到一个 AttributeError ,说 np.datetime64 对象没有这样的属性

Mar*_*anD 6

将其转换为 pandas Timestamp 对象:

import pandas as pd

t1 = pd.Timestamp(t)
Run Code Online (Sandbox Code Playgroud)

然后你可以使用

t1.hour
t1.minute
t1.second
Run Code Online (Sandbox Code Playgroud)

(与年、月、日等类似)从中获取个人项目。