time 库是 Python 中处理时间的标准库,包括:
- 计算机时间的表达
- 提取获取系统时间并格式化输出功能
- 提供系统级精确计时功能,用于程序性能分析
其导入需要 import 语句:
- import time(将整个time模块导入,在引用时格式为:time.<b>()。)
- from time import <b>(将time模块中的特定函数导入,在引用时格式为:<b>()。)
- from time import *(将整个time模块中的全部函数导入,在引用时格式为:<b>()。)
- import time as ...(将模块换个别名,如abc,在引用时格式为:abc.<b>()。)
time 库包括三类函数:
- 时间获取:time();ctime();gmtime()
- 时间格式化:strftime();strptime()
- 程序计时:sleep();perf_counter()
函数 |