python+selenium+new——格式化日期 ——文件夹路径
import time import os #-------------------------------------------------------------------------------- picture_time = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime(time.time())) print(picture_time) # 2020-02-15-19-18-38 #-------------------------------------------------------------------------------- picture_time2 = time.strftime("%Y-%m-%d", time.localtime(time.time())) print(picture_time2) # 2020-02-15 #-------------------------------------------------------------------------------- picture_time3 = time.strftime("%H-%M-%S", time.localtime(time.time())) print(picture_time3) # 2020-02-15 #-------------------------------------------------------------------------------- x = 'C:\\Users\\del\\Desktop\\'+picture_time2 os.mkdir(x) print(os.path.exists(x)) #判断此以日期命名的文件是否存在,#存在返回true, # 不存在返回false
执行结果:
2020-02-15-19-44-30
2020-02-15
19-44-30
True