怎么把Julian date转换成标准日期? [英] How to convert Julian date to standard date?
本文介绍了怎么把Julian date转换成标准日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串作为儒略历日期,例如 16152
表示2016年152日,或 15234
表示2015年第234天。
I have a string as Julian date like "16152"
meaning 152'nd day of 2016 or "15234"
meaning 234'th day of 2015.
如何将这些儒略日期转换为 2016/05/20
使用Python 3标准库吗?
How can I convert these Julian dates to format like 20/05/2016
using Python 3 standard library?
我可以像这样获得2016年: date = 20 + julian [0:1]
,其中 julian
是包含儒略日期的字符串,但是如何根据1月1日来计算其余部分?
I can get the year 2016 like this: date = 20 + julian[0:1]
, where julian
is the string containing the Julian date, but how can I calculate the rest according to 1th of January?
推荐答案
.strptime()
方法支持一年中的一天格式:
>>> import datetime
>>>
>>> datetime.datetime.strptime('16234', '%y%j').date()
datetime.date(2016, 8, 21)
然后您可以使用 strftime()
重新格式化日期
And then you can use strftime()
to reformat the date
>>> date = datetime.date(2016, 8, 21)
>>> date.strftime('%d/%m/%Y')
'21/08/2016'
这篇关于怎么把Julian date转换成标准日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文