from calendar import timegm from datetime import datetime, date import time def GetDateString(iso_string): print iso_string timestamp = timegm(time.strptime(iso_string.replace('Z', 'GMT'),'%Y-%m-%dT%H:%M:%S.%f%Z')) dt = datetime.utcfromtimestamp(timestamp) return dt.strftime('%Y-%m-%d') humanTime = '2012-06-10T16:36:20.509Z' # example from stackoverflow print GetDateString(humanTime) humanTime = '2017-06-26T17:28:29.555Z' # this one currently fails print GetDateString(humanTime) humanTime = '2017-06-10T00:00:00Z' # historically, this is what we receive from Landsat 8 print GetDateString(humanTime)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question