python3.6.1 time模块记录

本文介绍了Python3.6.1中time模块的使用,包括两种时间表示方式:浮点数秒数和九元素时间元组,以及DST(Daylight Saving Time)的概念,探讨了DST在时间表示中的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

time模块有两种表示时间的方式:一种是从世界标准时间开始计时,到其他时间之间总的秒数,是一个浮点类型的数字。另一种是用一个九个整数的元组表示时间,元组为

tuple =(year, month(1-12), day(1-31), hours(0-23), minutes(0-59), seconds(0-59), weekday(0-6, Monday is 0), Julian day(1-366), DST(-1, 0, 1))

其中DST表示采取的计时方式,1表示采用夏令时,0表示采用正常计时,-1表示由系统自行判断,采取合适的计时方式。

time模块的主要内容:

import time

#4 variables
print(time.timezone) #difference in seconds between UTC and local standard time
print(time.altzone) #difference in seconds between UTC and local DST time
print(time.daylight) #whether local time should reflect DST
print(time.tzname) #tuple of (standard time zone name, DST time zone)
#default
altzone = -32400
daylight = 0
timezone = -28800
tzname = ('\xd6\xd0\xb9ú±ê×\xbc\xca±\xbc\xe4', '\xd6\xd0\xb9ú\xcf\xc4\xc1\xee\xca±')
# 11 functions
print(time.time()) #return current time in seconds since Epoch as a float
print(time.clock()) #return CPU time since process start as a float
print(time.sleep(5)) #delay for a number of seconds given as a float
print(gmtime(0)) #convert seconds since Epoch to UTC tuple
print(localtime()) #convert seconds to local time tuple
print(mktime(time.localtime())) #convert local time tuple to seconds since Epoch
print(time.asctime()) #convert time tuple to string
print(time.ctime()) #convert time in seconds to string
print(time.strftime()) #convert time tuple to string according to format specification
print(time.strptime()) #convert string to time tuple
print(tzset()) #change the local timezone
asctime()函数的string形式为:
string = "Tue Jul 18 12:06:34 2017"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值