2

I am trying to extract the date as a string from an image in google earth engine, but can't seem to get it right. This is the code I have so far.

date = ee.Date(image.get('system:time_start'))

This returns an ee.date object in Python, but I can't find the right way to access the object. Date.getInfo() returns an error.

Does anyone know how to do this?

2 Answers 2

2

It is possible the access the date in the following way:

import ee

ee.Initialize()

collection = ee.ImageCollection('LANDSAT/LC08/C01/T1')

date = ee.Date(collection.first().get('system:time_start'))

date_dict = date.getInfo()

print "The number of milliseconds since 1970-01-01T00:00:00Z.: ", date_dict['value']

print "Formatted date", date.format('Y-M-d').getInfo()

Just calling ".getInfo()" on the ee.Date object will give you the number of milliseconds since 1970-01-01 in a Python dictionary.

It is possible to format the date with the ".format" method.

1
ee.Date(image.get('system:time_start')).format("yyyy-MM-dd")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.