简体   繁体   中英

Timestamp subtraction in ISO8601

I have a timestamp like this: 2021-01-03T01:59:00Z . How can I write a subtraction to get the timestamp a day earlier than the one indicated in ISO 8601 format?

Thanks!

You can use delta for take away 1 day

your_timestamp = '2021-01-03T01:59:00Z'
result = datetime.datetime.strptime(your_timestamp, "%Y-%m-%dT%H:%M:%S%z") - datetime.timedelta(days=1)

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