我有這個整數列表,需要使用python
將其轉換爲日期。Python將整數轉換爲日期
- 42222應該是2015年8月6日
- 42290應該是2015年10月13日
- 42319應該是二○一五年十一月一十一日
我得到的整數等於日期當i paste in to excel then format the cell to Date
。
我有這個整數列表,需要使用python
將其轉換爲日期。Python將整數轉換爲日期
我得到的整數等於日期當i paste in to excel then format the cell to Date
。
Excel的日期開始圍繞今年計數1900這將做到這一點:
from datetime import datetime, timedelta
def xldate_to_datetime(xldate):
tempDate = datetime(1900, 1, 1)
deltaDays =timedelta(days=int(xldate)-2)
TheTime = (tempDate + deltaDays)
return TheTime.strftime("%m/%d/%Y")
>>> xldate_to_datetime(42290)
'10/13/2015'
什麼是42222 ???它是單元格地址嗎? – orvi
'42222'如何等於'8/6/2015'? –
爲什麼downvotes,現在我不能問另一個問題.. @JF塞巴斯蒂安 – Kyrie