简体   繁体   中英

Converting string date to nanoseconds timestamp

I have a different time format than what I've found in different topics and I'm trying to convert it to timestamp.

timestamp_data= "2021-11-04 13:17:12.780000+00:00"
timestamp = datetime.datetime.strptime(timestamp_data, "%Y-%d-%m %H:%M:%S.%f+%z")

but it doesn't work.

Looked through the strptime documentation but didn't find proper arguments to use to match my date format.

As pointed out in the comments, remove the + in the format string.

timestamp_data= "2021-11-04 13:17:12.780000+00:00"
timestamp = datetime.datetime.strptime(timestamp_data, "%Y-%d-%m %H:%M:%S.%f%z")

will parse your string correctly.

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