python 示例
Python date.isoformat()方法 (Python date.isoformat() Method)
date.isoformat() method is used to manipulate objects of date class of module datetime.
date.isoformat()方法用于操作模块日期时间的日期类的对象。
It uses a date class object and returns a string representing the date in ISO 8601 format, YYYY-MM-DD. The International Standard for the representation of dates and times is ISO 8601. It was designed to provide a format of date and time representation free from any ambiguity. The format provides a standard approach and has the following rules:
它使用日期类对象,并以ISO 8601格式YYYY-MM-DD返回表示日期的字符串。 日期和时间表示的国际标准是ISO8601。该标准旨在提供日期和时间表示的格式,没有任何歧义。 该格式提供了一种标准方法,并具有以下规则:
Year first, followed by month, then the day, each separated by a hyphen ("-")
首先是年份,然后是月份,然后是日期,每个日期之间用连字符(“-”)分隔
Numbers less than 10 preceded by a leading zero
小于10的数字前加零
Module:
模块:
import datetime
Class:
类:
from datetime import date
Syntax:
句法:
isoformat()
Parameter(s):
参数:
None
没有
Return value:
返回值:
The return type of this method is a string in ISO 8601 format of the date.
此方法的返回类型是日期的ISO 8601格式的字符串。
Example:
例:
## importing date class
from datetime import date
## Creating an instance
x = date.today()
d = x.isoformat()
print("Normal format:",x)
print("ISO 8601 format:", d)
print()
x = date(2020,10,1)
print("Date 2020/10/1 in ISO 8601 format:", x.isoformat())
print()
x = date(200,10,12)
print("Date 200/10/12 in ISO 8601 format:", x.isoformat())
print()
x = date(1,1,1)
print("Date 1/1/1 in ISO 8601 format:", x.isoformat())
Output
输出量
Normal format: 2020-04-29
ISO 8601 format: 2020-04-29
Date 2020/10/1 in ISO 8601 format: 2020-10-01
Date 200/10/12 in ISO 8601 format: 0200-10-12
Date 1/1/1 in ISO 8601 format: 0001-01-01
翻译自: https://www.includehelp.com/python/date-isoformat-method-with-example.aspx
python 示例