MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何将整数日期格式转换为YYYYMMDD? (https://www.labfans.com/bbs/showthread.php?t=23304)

poster 2019-12-10 20:30

如何将整数日期格式转换为YYYYMMDD?
 
Python和Matlab经常具有整数日期表示,如下所示:

733828.0 733829.0 733832.0 733833.0 733834.0 733835.0 733836.0 733839.0 733840.0 733841.0

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

太感谢了!



[B]回答:[/B]

[URL="http://docs.python.org/library/datetime.html#datetime-objects"]datetime.datetime类[/URL]可以在这里为您提供帮助。如果将这些值视为整数天(您无需指定它们是什么),则可以使用以下方法。

>>> from datetime import datetime >>> dt = datetime.fromordinal(733828) >>> dt datetime.datetime(2010, 2, 25, 0, 0) >>> dt.strftime('%Y%m%d') '20100225' 您将值显示为浮点数,而上面的内容不使用浮点数。如果您可以提供有关数据是什么(数据来自何处)的更多详细信息,则可以给出更完整的答案。



[url=https://stackoverflow.com/questions/2623156]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 22:43

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.