简体   繁体   中英

Have to convert it into date time format

I have the data and in that data, time date format is of type 2017-11-01 00:00:00-04:00. I want to strip -4:00 and have to use the remaining.

I did everything but no successs.

from datetime import datetime
date_string = '2017-11-01 00:00:00-04:00'
date = datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S%z')

print(date)
# Returns: 2017-11-01 00:00:00-04:00

print(date.strftime("%Y-%m-%d %H:%M:%S"))
# Retruns: 2017-11-01 00:00:00

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