您的位置:首页 > 编程语言 > Python开发

python3.6.1 time模块记录

2017-07-18 14:43 260 查看
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"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python time class