简体   繁体   中英

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM