First look at the actual effect, now time 2018.4.26
Using a Python script to generate a multilevel catalog by month and day, the created directory can be easily consulted by placing the system-generated log files in it, with the following code:
#!/usr/bin/env python#Coding=utf-8Import TimeImportOS#string that gets the current system timeLocaltime=time.strftime ('%y-%m-%d%h:%m:%s', Time.localtime (Time.time ()))Print('localtime='+localtime)#System Current Time yearYear=time.strftime ('%Y', Time.localtime (Time.time ()))#MonthMonth=time.strftime ('%m', Time.localtime (Time.time ()))#DateDay=time.strftime ('%d', Time.localtime (Time.time ()))#time-specific hours, minutes, millisecondsMdhms=time.strftime ('%m%d%h%m%s', Time.localtime (Time.time ())) Fileyear=OS.GETCWD () +'/upload_files/'+ '/' +Yearfilemonth=fileyear+'/'+Monthfileday=filemonth+'/'+ Dayif notos.path.exists (fileyear): Os.mkdir (fileyear) os.mkdir (filemonth) os.mkdir (fileday)Else: if notos.path.exists (filemonth): Os.mkdir (Filemonth) os.mkdir (fileday)Else: if notos.path.exists (fileday): Os.mkdir (Fileday)#create a file with ' Timefile_ ' + specific time for the file namefiledir=fileday+'/timefile_'+mdhms+'. txt' out=open (Filedir,'W')#writes the current system time string to the fileOut.write ('localtime='+localtime) out.close ()
Additional knowledge points about date and time
Import= Datetime.date.today ()
I want to make it this way.
Importdatetime#This is the designation 2008/12/5 23:59:59Today = Datetime.datetime (2008, 12, 5, 23, 59, 59) #datetime can also be added minus, one second at a time.x = datetime.timedelta (seconds = 1) y= Datetime.date (2008, 12, 5, 23, 59, 59) W= x +y#w = datetime.datetime (6, 0, 0) #One plus 23 hours, 59 minutes, 59 seconds .x = Datetime.timedelta (hours = all, minutes = seconds = 59) W= W +x#w = datetime.datetime (6 , +,--)
What's more, if you want to get today's year, month, day is also very simple to say
Import# now in the time #x = Datetime.datetime (5, (+), #指定時間) # will get the # # will get # # will get 5x.hour # # points # seconds
Python method for creating multilevel catalogs by current date (year, month, day)