'What is the time format used in KML files?
I am parsing a KML file on the iPhone, and I need to know what the time format of this string from the KML file is: 2011-05-16T08:00:59Z.
I think it is somewhere along the lines of the following, but I don't know what the Z stands for: YYYY-MM-ddTHH:mm:ss.
Solution 1:[1]
Solution 2:[2]
I use this in Python to convert Django objects into KML TimeStamp (notice the capital S in TimeStamp - that threw me for a while):
from datetime import datetime
from pytz import timezone
# Access the Date Time of the created object
dtg = str(loc.created_at)
# Import the Django timestamp (which includes miliseconds)
datetime_obj = datetime.strptime(dtg, "%Y-%m-%d %H:%M:%S.%f+00:00")
# Convert it to UTC Format
datetime_obj_utc = datetime_obj.replace(tzinfo=timezone('UTC'))
# Convert it to Zulu time
date_time = datetime_obj_utc.strftime('%Y-%m-%dT%H:%M:%SZ')
# Build the KML output
output += ' <Placemark><name>Feature</name>\n'
output += ' <TimeStamp><when>'+date_time+'</when></TimeStamp>\n'
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | phihag |
| Solution 2 | JayCrossler |
