gpt4 book ai didi

python - 从 Python 中的 float 中获取日期时间

转载 作者:IT老高 更新时间:2023-10-28 20:50:15 26 4
gpt4 key购买 nike

如何从 Python 中的 float 获取 datetime

例如,我有一个 float ,例如 43111.0,我想为此获取 datetime

最佳答案

看起来像 Excel 日期时间格式,称为 serial date .快速而肮脏的转换方式:

>>> import datetime
>>> serial = 43111.0
>>> seconds = (serial - 25569) * 86400.0
>>> datetime.datetime.utcfromtimestamp(seconds)
datetime.datetime(2018, 1, 11, 0, 0)

关于python - 从 Python 中的 float 中获取日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6706231/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com