时间获取:

time()--返回浮点数
ctime() --返回字符串
gmtime() --返回计算机可处理的时间格式

时间格式化:

strftime(tpl,ts)  --time to string,其中tpl是格式化字符串,ts是计算机时间变量
strptime(str,tpl) --str to time,其中tpl是输入格式,str是字符串

例子:

Python学习笔记 Part05--time库的使用

其中,格式化字符串的控制符有:

Python学习笔记 Part05--time库的使用

Python学习笔记 Part05--time库的使用

程序计时应用

程序计时应用perf_counter()
程序产生时间sleep()--单位是s
def wait():
  time.sleep(3.3)
wait()
Python学习笔记 Part05--time库的使用

学习链接--Python语言程序设计

相关文章: