本节介绍 Python内置模块 time、datetime、calendar的常用用法。
time
time模块提供各种操作时间的函数。
说明:一般有两种表示时间的方式:
1.时间戳的方式(相对于1970.1.1 00:00:00以秒计算的偏移量),时间戳是惟一的
2.以数组的形式表示即(struct_time),共有九个元素,分别表示,同一个时间戳的struct_time会因为时区不同而不同
time() — 返回时间戳
sleep() — 延迟运行单位为s
gmtime() — 转换时间戳为时间元组(时间对象)
localtime() — 转换时间戳为本地时间对象
asctime() — 将时间对象转换为字符串
ctime() — 将时间戳转换为字符串
mktime() — 将本地时间转换为时间戳
strftime() — 将时间对象转换为规范性字符串
…
领取专属 10元无门槛券
私享最新 技术干货