Date iso format python

106 Views Asked by At

I have this date form in python that I am writing on an api: 2022-06-01T10:36:56.000Z How can I turn this into a second? Thanks for your comments

I would like to use the seconds I have to do addition division and then go back to day/date/hour format

I can't find any content on the internet

1

There are 1 best solutions below

1
On

Python cannot handle all type of iso formatted date strings. So you can use isodate library or remove .000Z from the string parsing.

You can be more clear on seconds though, is it total seconds elapsed from 1970, Jan 1 or seconds part in the date ?

k = datetime.fromisoformat("2022-06-01T10:36:56.000Z".replace(".000Z", ""))
k.timestamp()