--Get the date and convert it to a string --Organized for frequent use in file names, etc.
datetime
--Output the current date
Execution date
# yyyymmdd
yyyymmdd = datetime.date.today().strftime('%Y%m%d')
print(yyyymmdd)
# yyyy/mm/dd
yyyymmdd = datetime.date.today().strftime('%Y/%m/%d')
print(yyyymmdd)
# yyyy-mm-dd
yyyymmdd = datetime.date.today().strftime('%Y-%m-%d')
print(yyyymmdd)
result
20200917
2020/09/17
2020-09-17
--Add time to execution date and time and output
--Display format is yyyymmddhhmmss
Execution date
yyyymmdd_hms = datetime.date.now().strftime('%Y%m%d%H%M%S')
print(yyyymmdd_hms)
result
20200917155026
Use strftime ()
Click here for the format code [format code for strftime () and strptime ()]
(https://docs.python.org/ja/3/library/datetime.html#strftime-and-strptime-format-codes)
Recommended Posts