如何将整数日期格式转换为YYYYMMDD? [英] How to convert the integer date format into YYYYMMDD?

查看:160
本文介绍了如何将整数日期格式转换为YYYYMMDD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python和Matlab经常具有如下所示的整数日期表示形式:

Python and Matlab quite often have integer date representations as follows:

733828.0 733829.0 733832.0 733833.0 733834.0 733835.0 733836.0 733839.0 733840.0 733841.0

733828.0 733829.0 733832.0 733833.0 733834.0 733835.0 733836.0 733839.0 733840.0 733841.0

这些数字对应于今年的某些日期.你们知道哪个功能可以将它们转换回YYYYMMDD格式吗?

these numbers correspond to some dates this year. Do you guys know which function can convert them back to YYYYMMDD format?

感谢一百万!

推荐答案

datetime.datetime可以在这里为您提供帮助.如果将这些值视为整数天(您无需指定它们的值),则可以使用以下方法.

The datetime.datetime class can help you here. The following works, if those values are treated as integer days (you don't specify what they are).

>>> from datetime import datetime
>>> dt = datetime.fromordinal(733828)
>>> dt
datetime.datetime(2010, 2, 25, 0, 0)
>>> dt.strftime('%Y%m%d')
'20100225'

您将值显示为浮点数,而上面的内容不使用浮点数.如果您可以提供有关数据是什么(以及数据来自何处)的更多详细信息,则可以给出更完整的答案.

You show the values as floats, and the above doesn't take floats. If you can give more detail about what the data is (and where it comes from) it will be possible to give a more complete answer.

这篇关于如何将整数日期格式转换为YYYYMMDD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆