Python标准库系列文章目录
python内建模块
collections 模块:deque双向队列
queue module:队列、优先级队列
sortedcontainers:有序列表、有序字典和有序集合
描述
time模块提供了多种操纵时间的函数
有两种方式表述时间。
1、xxxxxxxxx.xxxxxx秒,周期为epoch,此法为 UTC(a.k.a. GMT)
2、tuple(int1, int2, int3, int4, int5, int6, int7, in8, int9)
| | |
|–|:–|–|
| 1 |year(including century, e.g. 198) |
| 2| month(1-12)|
| 3 | day(1-31)|
| 4 | hours(0-23)|
| 5 | minutes(0-59)|
| 6 | seconds(0-59)|
| 7 | weekday(0-6, Monday is 0)|
| 8 | Julian day(day in the year, 1-366)|
|9|DST(Daylight Savings Time) flag(-1,0,1)|;
If the DST flag is 0, the time is given in the regular time zone;
if it is 1, the time is given in the DST time zone;
if it is -1, mktime() should guess based on the date and time.
一、类
builtins.tuple(builtins.object)
struct_time
class struct_time(builtins.tuple)
| The time value as returned by gmtime(), localtime(), and strptime(), and
| accepted by asctime(), mktime() and strftime(). May be considered as a
| sequence of 9 integers.
|
| Note that several fields' values are not the same as those defined by
| the C language standard for struct tm. For example, the value of the
| field tm_year is the actual year, not year - 1900. See individual
| fields' descriptions for details.
二、函数
name | return | e.g. |
---|---|---|
asctime | right-aligned asctime(…) asctime([tuple]) -> string Convert a time tuple to a string, e.g. ‘Sat Jun 06 16:26:11 1998’. When the time tuple is not present, current time as returned by localtime() is used. 输入:第二种表示方式,若为空默认输入localtime() 输出:str格式的当前时间 | asctime() 返回当前系统时间 “Sat Jan 15 21:59:40 2022” |
clock | clock() -> floating point number 返回CPU时间or 实时,从进程开始或者第一次调用clock() 这和系统记录一样精确 | 返回距离第一次调用clock()过了多少秒,精确到小数点后7位 |
ctime | 输入:时间的第一种表示方式,若为空,默认返回当前时间 返回:当前时间str | ctime()返回结果同asctime() |
gmtime 不太能和其它函数兼容 | 输入:seconds,若为空则为当前时间 输出:struct_time (tuple) 该函数输入和返回都为英国0经度的时间 | 将时间的第一种表示方式转化为时间的第二种表示方式 |
localtime | 输入:seconds,若为空则为当前时间 输出:struct_time (tuple) | 将时间的第一种表示方式转化为时间的第二种表示方式 |
mktime | 输入:struct_time (tuple),不能为空 返回:floating point number | 将时间的第二种表示方式转化为时间的第一种表示方式 该输出精度较低 |
monotonic | 获取单调时钟的值,仅连续调用的结果之间的差有效 在长时间运行过程中测量经过时间的方法 | |
perf_count | 有点像monotonic但精度更高 | |
sleep | 程序暂停xx.xx秒 | |
time | 返回时间的第一种表示方式 |