[英]How can I convert a gregorian time vector into datetime in Python?
I have a vector of time in Gregorian type.我有一个公历类型的时间向量。 I want to convert it in the common format of dates with year, month, day, hour, minute and seconds.
我想将其转换为带有年、月、日、小时、分钟和秒的常用日期格式。
I tried this:我试过这个:
from datetime import datetime
datetime.fromordinal(736364.94)
It returns always something only with the information of year, month and day.它总是只返回带有年、月和日信息的东西。 Like this:
像这样:
datetime.datetime(2017, 2, 4, 0, 0)
I was expecting a date with hours, minutes and seconds information我期待一个包含小时、分钟和秒信息的日期
I think the ordinal is for days only, but assuming the decimal is representative of the fraction of the day you can use this.我认为序数仅适用于天数,但假设小数代表一天中可以使用的分数。
import datetime
datetime.fromordinal(int(736364.94))+datetime.timedelta(days=736364.94%1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.