How to easily distinguish between strftime and strptime

Time conversion

Time conversion
strftime converts time from computer format to custom format

import datetime
present = datetime.datetime.now() #Get the present moment (computer format)
now=datetime.datetime.now().strftime('%Y-%m-%d-%H') #Convert the computer format For a custom format
now1=datetime.datetime.now().strftime('%Y%m%d%H') #Convert the computer format to a custom format

strptime converts the time from a custom format to a computer format

from datetime import datetime
val='2021-03-15-11'
val_time=datetime. strptime(val,'%Y-%m-%d-%H') #Convert custom format time to computer format
val1=' 2021-03-15-11-13-11'

 A table allows you to easily understand strftime and strptime

Guess you like

Origin blog.csdn.net/lc_lcrystal/article/details/115183136