3
A
回答
15
我建议如下:
import datetime
date = datetime.datetime.strptime("111609", "%m%d%y")
print date.strftime("%m/%d/%Y")
这将010199
转换为01/01/1999
和010109
到01/01/2009
。
0
date = '111609'
new_date = date[0:2] + '/' + date[2:4] + '/' + date[4:6]
0
>>> s = '111609'
>>> d = datetime.date(int('20' + s[4:6]), int(s[0:2]), int(s[2:4]))
>>> # or, alternatively (and better!), as initially shown here, by Tim
>>> # d = datetime.datetime.strptime(s, "%m%d%y")
>>> d.strftime('%m/%d/%Y')
'11/16/2009'
为何strptime()方法更好,其中一个原因是,它的日期接近当代的交易,有一个窗口,即妥善处理日期在20世纪后期和恰逢21世纪初。
-1
不完整的,但这里有一个想法
11/16/2009
date_var = ("11/16/2009")
datetime.date.replace(year=2009, month=11, day=16)
相关问题
- 1. PHP/Python的日期转换
- 2. Python日期到EPOCH转换
- 3. Python:日期转换错误
- 4. 在Python中转换日期
- 5. 转换日期到月和日python?
- 6. 从python列表中的日期转换
- 7. 的Python:到日期转换为datetime
- 8. Python的 - 转换日期为ISO 8601
- 9. Python中日期格式的转换
- 10. Python的日期时间格式转换
- 11. 日期转换
- 12. 日期转换
- 13. 日期转换
- 14. 日期转换
- 15. 转换日期
- 16. 日期转换
- 17. Python的转换日期字符串到日期时间
- 18. Oracle日期转换为Python中的日期时间
- 19. 将xldate转换为python日期时间
- 20. Python用户输入和日期转换
- 21. 在python中将日期转换为Int
- 22. Python日期时间格式转换
- 23. 将日期转换为序数python?
- 24. Python将整数转换为日期
- 25. Python日期翻转
- 26. 将日期字符串(YYYY/YYYY_mm.mdf)转换为可用日期Python
- 27. Python将秒转换为日期时间日期和时间
- 28. 转换日期字符串到日期在python
- 29. 在Python中将写入日期转换为日期格式
- 30. Js将日期对象转换为python日期时间
错过了四位数年份部分。那么如果日期是“010199”呢? – 2009-11-16 21:51:31
这个问题需要4位数的年份,而不仅仅是原始字符串 – 2009-11-16 21:52:03
的2位数字。失败我的一部分。我只回答,因为它看起来像OP想要一个黑客一起回答。日期时间ftw,imo。 – physicsmichael 2009-11-16 22:12:09