python 示例_带有示例的Python date isoformat()方法

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。该标准旨在提供日期和时间表示的格式,没有任何歧义。 该格式提供了一种标准方法,并具有以下规则:

  1. Year first, followed by month, then the day, each separated by a hyphen ("-")

    首先是年份,然后是月份,然后是日期,每个日期之间用连字符(“-”)分隔

  2. 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 示例

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值