简体   繁体   中英

Convert datetime format to "YYYY-MM-DD HH:MM:SS" string in Python

I am extracting date from Sql Query executed using selenium Python. The date variable shows up as datetime.datetime(2020, 8, 27, 4, 16, 33) and I need to change the format in "YYYY-MM-DD HH:MM:SS". Please help.

import datetime
x = datetime.datetime(2020, 8, 27, 4, 16, 33)

x.strftime('%Y-%m-%d %H:%M:%S')

it returns

'2020-08-27 04:16:33'

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