Python time module

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.

二、函数

namereturne.g.
asctimeright-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”
clockclock() -> 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返回时间的第一种表示方式
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值