python模块------time
说明
time模块提供各种时间相关的功能 与时间相关的模块有:time,datetime,calendar
这个模块的功能不是适用于所有的平台 这个模块中定义的大部分函数是调用C平台上的同名函数实现
time是python自带的模块,用于处理时间问题,提供了一系列的操作时间的函数
用法
1、time.sleep(secs)
可以实现在python程序中的延时,单位为秒,并支持浮点数非整数秒的延时。例:
import time
for i in range(3):
time.sleep(2)
print("hello word")
2、时间获取
time.strftime("%Y-%m-%d %H:%M:%S") #格式化时间
time.time()#获得当前时间的时间戳
实例
1、创建以时间为名称的文件夹
[root@node5801 test]# more 1.py
#!/usr/bin/python
import time
import os
date = time.strftime("%Y-%m-%d")
os.mkdir(date)
[root@node5801 test]# python 1.py
[root@node5801 test]# ls
1.py 2020-07-01
官方文档:https://docs.python.org/3/library/time.html#time.struct_time
---当才华撑不起你的野心的时候,请努力!---

浙公网安备 33010602011771号