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

python 示例

Python date.timetuple()方法 (Python date.timetuple() Method)

date.timetuple() method is used to manipulate objects of date class of module datetime.

date.timetuple()方法用于操作模块datetime的日期类的对象。

It is an instance method which means that it works on an instance of the class. It returns a time.struct_time which is an object with a named tuple interface containing nine elements.

这是一个实例方法,这意味着它可以在类的实例上工作。 它返回一个time.struct_time ,它是一个具有包含9个元素的命名元组接口的对象。

Following values are present in time.struct_time object:

time.struct_time对象中存在以下值:

IndexAttributeValue
0tm_year(for example, 1993)
1tm_monrange [1, 12]
2tm_mdayrange [1, 31]
3tm_hourrange [0, 23]
4tm_minrange [0, 59]
5tm_secrange [0, 61]
6tm_wdayrange [0, 6], Monday is 0
7tm_ydayrange [1, 366]
8tm_isdst0, 1 or -1; see below
N/Atm_zoneabbreviation of timezone name
N/Atm_gmtoffoffset east of UTC in seconds
指数 属性
0 tm_year (例如1993)
1个 tm_mon 范围[1,12]
2 tm_mday 范围[1,31]
3 tm_hour 范围[0,23]
4 tm_min 范围[0,59]
5 tm_sec 范围[0,61]
6 tm_wday 范围[0,6],星期一为0
7 tm_yday 范围[1,366]
8 tm_isdst 0、1或-1; 见下文
不适用 tm_zone 时区名称的缩写
不适用 tm_gmtoff 以秒为单位偏移UTC以东

A date timetuple is equivalent to,

日期时间元组等于

    time.struct_time((d.year, d.month, d.day, 0, 0, 0, d.weekday(), yday, -1))

Since it is a date object, time values are missing because of which those attributes are set to zero(index- 3,4,5). As date object is naive, the timezone information are also missing.

由于它是一个日期对象,因此缺少时间值,因此这些属性设置为零(索引3、4、5)。 由于日期对象太幼稚,因此时区信息也丢失了。

Module:

模块:

    import datetime

Class:

类:

    from datetime import date

Syntax:

句法:

    timetuple()

Parameter(s):

参数:

  • None

    没有

Return value:

返回值:

The return type of this method is a time.struct_time object which contains date information.

此方法的返回类型是time.struct_time对象,其中包含日期信息。

Example:

例:

## Python program explaining the 
## use of date class instance methods

from datetime import date

## Creating an instance
x = date(2020, 4, 29)
print("Current date is:", x)
print()

d = x.timetuple()
print("The tuple of the date object", d)
print()

print("We can also access individual elements of this tuple")
for i in d:
    print(i)

Output

输出量

Current date is: 2020-04-29

The tuple of the date object time.struct_time(tm_year=2020, tm_mon=4, tm_mday=29, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=120, tm_isdst=-1)

We can also access individual elements of this tuple
2020
4
29
0
0
0
2
120
-1


翻译自: https://www.includehelp.com/python/date-timetuple-method-with-example.aspx

python 示例

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值