#!/usr/bin/env python#coding=utf-8import timeimport os.path#获得当前系统时间的字符串localtime=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))print('localtime='+localtime)#系统当前时间年份year=time.strftime('%Y',time.localtime(time.time()))#月份month=time.strftime('%m',time.localtime(time.time()))#日期day=time.strftime('%d',time.localtime(time.time()))#具体时间 小时分钟毫秒mdhms=time.strftime('%m%d%H%M%S',time.localtime(time.time()))fileYear='/data/python-scripts/inspector/AccountInspector/badJsidAccountLogs/'+yearfileMonth=fileYear+'/'+monthfileDay=fileMonth+'/'+dayif not os.path.exists(fileYear): os.mkdir(fileYear) os.mkdir(fileMonth) os.mkdir(fileDay)else: if not os.path.exists(fileMonth): os.mkdir(fileMonth) os.mkdir(fileDay) else: if not os.path.exists(fileDay): os.mkdir(fileDay)#创建一个文件,以‘timeFile_'+具体时间为文件名称fileDir=fileDay+'/timeFile_'+mdhms+'.txt'out=open(fileDir,'w')#在该文件中写入当前系统时间字符串out.write('localtime='+localtime)out.close()