11 Use of time library for python to obtain system time

11 Use of time library for python to obtain system time

Get Time

import time
time.time() #获取从1970.1.1 0:00到现在有多少秒, 是一个浮点数
time.ctime() 这个函数可以获取一个易于读取的时间格式,格式为字符串格式
time.gmtime() 返回计算机程序可处理的时间格式,struct_time格式,是一个结构体

Time formatting

Insert picture description here
Insert picture description here
Insert picture description here
The strptime() function and strtime() function are complementary, he turns a string of characters into time

Insert picture description here

Program timing

Measuring time perf_counter()
produces time sleep()
Note the time difference calculated here

Note the time difference calculated here

Insert picture description here

Guess you like

Origin blog.csdn.net/bj_zhb/article/details/104868259