ee.Date.parse

  • ee.Date.parse() allows you to convert a date string into a Date object by specifying the string's format.

  • It accepts a format pattern based on Joda-Time's DateTimeFormat, the date string itself, and an optional time zone (defaulting to UTC).

  • Various format patterns can be used, such as 'YYYY MM dd', 'YYYY-MM-dd', 'YYYY/MM/dd', 'MM/dd/YY', 'MMM.dd, YYYY', and 'YYYY-MM-dd HH:mm:ss'.

Parse a date string, given a string describing its format.

UsageReturns
ee.Date.parse(format, date, timeZone)Date
ArgumentTypeDetails
formatStringA pattern, as described at http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html.
dateStringA string matching the given pattern.
timeZoneString, default: nullThe time zone (e.g., 'America/Los_Angeles'); defaults to UTC.

Examples

Code Editor (JavaScript)

print(ee.Date.parse('yyyy MM dd', '2021 4 30'));
print(ee.Date.parse('yyyy-MM-dd', '2021-4-30'));
print(ee.Date.parse('yyyy/MM/dd', '2021/4/30'));
print(ee.Date.parse('MM/dd/yy', '4/30/21'));
print(ee.Date.parse('MMM. dd, yyyy', 'Apr. 30, 2021'));
print(ee.Date.parse('yyyy-MM-dd HH:mm:ss', '2021-4-30 00:00:00'));

Python setup

See the Python Environment page for information on the Python API and using geemap for interactive development.

import ee
import geemap.core as geemap

Colab (Python)

display(ee.Date.parse('YYYY MM dd', '2021 4 30'))
display(ee.Date.parse('YYYY-MM-dd', '2021-4-30'))
display(ee.Date.parse('YYYY/MM/dd', '2021/4/30'))
display(ee.Date.parse('MM/dd/YY', '4/30/21'))
display(ee.Date.parse('MMM. dd, YYYY', 'Apr. 30, 2021'))
display(ee.Date.parse('YYYY-MM-dd HH:mm:ss', '2021-4-30 00:00:00'))