将日期转换为序数python? [英] Convert date to ordinal python?
本文介绍了将日期转换为序数python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想转换2010-03-01至733832
I want to convert 2010-03-01 to 733832
我刚刚找到了这个常规代码
I just found this toordinal code
d=datetime.date(year=2010, month=3, day=1)
d.toordinal()
来自此
但是我想要更多类似的东西
But i want something more like
d=datetime.date('2010-03-01')
d.toordinal()
预先感谢
推荐答案
您将需要使用在这种情况下,对 date
方法的调用是多余的,仅用于使该对象与 date
对象而不是 datetime
对象.
The call to the date
method in this case is redundant, and is only kept for making the object consistent as a date
object instead of a datetime
object.
如果您希望处理更多的日期字符串格式, Python的strftime指令是您要检查的一个很好的参考.
If you're looking to handle more date string formats, Python's strftime directives is one good reference you want to check out.
这篇关于将日期转换为序数python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文