AI-generated Key Takeaways
-
The
Date.get()
method returns the specified unit of a date as a Long value. -
This method takes a required
unit
argument, which can be 'year', 'month', 'week', 'day', 'hour', 'minute', or 'second'. -
An optional
timeZone
argument can be provided to specify the time zone for the calculation.
Usage | Returns |
---|---|
Date.get(unit, timeZone) | Long |
Argument | Type | Details |
---|---|---|
this: date | Date | |
unit | String | One of 'year', 'month' (returns 1-12), 'week' (1-53), 'day' (1-31), 'hour' (0-23), 'minute' (0-59), or 'second' (0-59). |
timeZone | String, default: null | The time zone (e.g., 'America/Los_Angeles'); defaults to UTC. |
Examples
Code Editor (JavaScript)
var date = ee.Date('2021-4-30T07:15:31'); print('Year', date.get('year')); print('Month', date.get('month')); print('Week', date.get('week')); print('Day', date.get('day')); print('Hour', date.get('hour')); print('Minute', date.get('minute')); print('Second', date.get('second'));
import ee import geemap.core as geemap
Colab (Python)
date = ee.Date('2021-4-30T07:15:31') display('Year:', date.get('year')) display('Month:', date.get('month')) display('Week:', date.get('week')) display('Day:', date.get('day')) display('Hour:', date.get('hour')) display('Minute:', date.get('minute')) display('Second:', date.get('second'))