python中的date.toordinal()的倒数是多少? [英] What is the inverse of date.toordinal() in python?

查看:1287
本文介绍了python中的date.toordinal()的倒数是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python中,一个日期对象可以通过以下方式转换为proclptic格里高利序数:

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()

但是反向操作是什么?

推荐答案

相反的是 date.fromordinal


classmethod date.fromordinal(ordinal)

    返回对应于proleptic Gregorian ordinal,
,其中1年1月1日的序数为1. ValueError被提升,除非
1< = ordinal< = date.max.toordinal()。对于任何日期d,
date.fromordinal(d.toordinal())== d。

    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.

这篇关于python中的date.toordinal()的倒数是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆