What is the inverse of date.toordinal() in python?

前端 未结 3 1474
鱼传尺愫
鱼传尺愫 2021-02-20 00:51

In python, a dateobject can be converted in the proleptic Gregorian ordinal this way:

d=datetime.date(year=2010, month=3, day=1)
d.toordinal()
         


        
3条回答
  •  醉酒成梦
    2021-02-20 01:18

    It's date.fromordial() as Jon wrote in the comments.

    or datetime.fromordinal()

    You can read more about it in the date= documentation

    and for datetime

    From the docs:

    classmethod date.fromordinal(ordinal)

    Return the date corresponding to the proleptic Gregorian ordinal, where January 1 of year 1 has ordinal 1. ValueError is raised unless 1 <= ordinal <= date.max.toordinal().

    For any date d, date.fromordinal(d.toordinal()) == d.

提交回复
热议问题