简体   繁体   中英

how to convert date to other format with special chars

I'd like to convert date to such format:

2017%2C01%2C02

was trying to do this using:

date.strftime('%Y%2Cm%2Cd')

But is doesn't work.

Can anyone explain what I am doing wrong and how to solve it ?

Thanks,

In order for strftime to print % as a literal string, you need to escape it by doing %% . You also need to add another % in front of m and d like you did with Year, if you want them to be replaced by actual month and dates.

This cheat sheet is quite helpful.

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