Changing Time from Epoch Time to Iso Format in Python [Duplicate]
I Would Like to Change the Time from Epoch Time to a Format Readable by Kml Extensions (Such as Iso Format of Time). There Is Plenty of Help to Change from...
I would like to change the time from epoch time to a format readable by Kml extensions (such as iso format of time).
There is plenty of help to change from epoch to formats like YYYYMMDDHHMMSS and other structs using tuples and mktime, but to .iso formation , i haven't been able to find it.
utcfromtimestamp converts seconds since the epoch to the corresponding UTC datetime.datetime.
datetime.datetime objects have a isoformat method which returns the date as a string in ISO 8601 format.
In [6]: import datetime as DT
In [7]: seconds_since_epoch = 0
In [8]: DT.datetime.utcfromtimestamp(seconds_since_epoch)
Out[8]: datetime.datetime(1970, 1, 1, 0, 0)
In [9]: DT.datetime.utcfromtimestamp(seconds_since_epoch).isoformat()
Out[9]: '1970-01-01T00:00:00'