import datetime now_time = datetime.datetime.now() print(now_time.strftime(‘%Y-%m-%d %H:%M:%S‘))
引用:http://www.jb51.net/article/67828.htm
如果结合对文件修改的时候需要把获取到的时间放置文件名中可以通过只去格式化的部分值插入到新命名str中
import datetime from xlrd import open_workbook from xlutils.copy import copy now_time = datetime.datetime.now() now_time_year = now_time.strftime(‘%Y-%m-%d‘) now_time_H = now_time.strftime(‘%H‘) now_time_M = now_time.strftime(‘%M‘) now_time_S = now_time.strftime(‘%S‘) rb = open_workbook(‘D:\qiuwenbin.xlsx‘) wb = copy(rb) ws = wb.get_sheet(0) ws.write(1,1,283) wb.save(‘D:\qiuwenbin({},{}时{}分{}秒).xlsx‘.format(now_time_year,now_time_H,now_time_M,now_time_S))
时间: 2024-10-15 15:12:54