📜  PythonDatetime.date类的toordinal()函数

📅  最后修改于: 2022-05-13 01:54:47.523000             🧑  作者: Mango

PythonDatetime.date类的toordinal()函数

toordinal()函数用于返回指定日期时间实例的预测格里高利序数。

注意: Proleptic Gregorian ordinal 给出了从 01/Jan/0001 开始经过的天数。这里的序数被称为 Proleptic,因为公历本身是从 1582 年 10 月开始的。

示例 1:使用今天的日期。

Python3
# Python3 code to demonstrate
# Getting the proleptic Gregorian
# ordinal of a datetime instance
  
# importing datetime and time module
import datetime
import time
  
# Getting today's date
todays_Date = datetime.date.fromtimestamp(time.time());
  
# Calling the toordinal() function over the
# today's date
date = todays_Date.toordinal();
  
# Printing the proleptic Gregorian ordinal
# for the today's date
print("Proleptic Ordinal for today's date: %s"%date);


Python3
# Python3 code to demonstrate
# Getting the proleptic Gregorian
# ordinal of a datetime instance
  
# importing datetime and time module
import datetime
import time
  
# Getting today's date and time
todays_DateTime = datetime.datetime.now();
  
# Calling the toordinal() function over the
# today's date and time
DateTime = todays_DateTime.toordinal();
  
# Printing the proleptic Gregorian ordinal
# for the today's date and time
print("Proleptic Ordinal for today's date and time: %s"%DateTime);


Python3
# Python3 code to demonstrate
# Getting the proleptic Gregorian
# ordinal of a datetime instance
  
# importing datetime and time module
import datetime
import time
  
# Initializing a date and time
DateTime = datetime.datetime(1358, 8, 12, 1, 3, 4, 9);
  
# Calling the toordinal() function over the
# above date and time
Date_Time = DateTime.toordinal();
  
# Printing the proleptic Gregorian ordinal
# for the above given date and time
print("Proleptic Ordinal for today's date and time: %s"%Date_Time);


输出:

Proleptic Ordinal for today's date: 737998

示例 2:使用今天的日期和时间。

蟒蛇3

# Python3 code to demonstrate
# Getting the proleptic Gregorian
# ordinal of a datetime instance
  
# importing datetime and time module
import datetime
import time
  
# Getting today's date and time
todays_DateTime = datetime.datetime.now();
  
# Calling the toordinal() function over the
# today's date and time
DateTime = todays_DateTime.toordinal();
  
# Printing the proleptic Gregorian ordinal
# for the today's date and time
print("Proleptic Ordinal for today's date and time: %s"%DateTime);

输出:

Proleptic Ordinal for today's date and time: 737998

示例 3:使用特定日期。

蟒蛇3

# Python3 code to demonstrate
# Getting the proleptic Gregorian
# ordinal of a datetime instance
  
# importing datetime and time module
import datetime
import time
  
# Initializing a date and time
DateTime = datetime.datetime(1358, 8, 12, 1, 3, 4, 9);
  
# Calling the toordinal() function over the
# above date and time
Date_Time = DateTime.toordinal();
  
# Printing the proleptic Gregorian ordinal
# for the above given date and time
print("Proleptic Ordinal for today's date and time: %s"%Date_Time);

输出:

Proleptic Ordinal for today's date and time: 495858