简体   繁体   English

如何在 Python 中将公历时间向量转换为日期时间?

[英]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.

相关问题 如何将 100 纳秒的公历 bigint 值转换为 Python 中的日期时间? - How do I convert a 100 nanosecond Gregorian bigint value to a datetime in Python? 如何在Python中将日期时间字符串中的时间从24:00转换为00:00? - How can I convert the time in a datetime string from 24:00 to 00:00 in Python? 如何在 Python 中将日期时间对象转换为自纪元(unix 时间)以来的毫秒数? - How can I convert a datetime object to milliseconds since epoch (unix time) in Python? 如何将该日期和时间格式转换为datetime? - How can I convert this date and time format to datetime? 如何使用 datetime 将 int 转换为时间 - How can I convert int to time using datetime 在python pandas中,如何将此格式化的日期字符串转换为datetime - In python pandas, how can I convert this formatted date string to datetime Python:如何在不知道格式的情况下将字符串转换为日期时间? - Python: How can I convert string to datetime without knowing the format? 如何从 IntgerField(Timestamp) 转换为 python 日期时间 - How can i convert from IntgerField(Timestamp) to python datetime 如何将日期时间转换为 python 中的 unix 时间戳 - How can I convert datetime to unix timestamp in python 在python中将日期时间转换为时间 - Convert datetime to time in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM