简体   繁体   中英

Date in format of YYYYMMDD rather than YYYY-MM-DD in python

The files I need to move has a pattern of date like this: 20190328 .

My datetime module gives me the date as YYYY-MM-DD . How can I get the date in form YYYYMMDD ?

Using strftime :

import datetime
print(datetime.datetime.now().strftime("%Y%m%d"))

OUTPUT:

20190328

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM