AI-generated Key Takeaways
-
The
Date.advance
method creates a new Date by adding a specified delta and unit to a given Date. -
The
delta
argument is a Float representing the amount to add, and theunit
is a String specifying the unit of time ('year', 'month', 'week', 'day', 'hour', 'minute', or 'second'). -
An optional
timeZone
argument can be provided as a String to specify the time zone, defaulting to UTC. -
The method returns a new Date object.
-
Examples are provided in both JavaScript and Python demonstrating how to use the
advance
method with positive and negative delta values.
Usage | Returns |
---|---|
Date.advance(delta, unit, timeZone) | Date |
Argument | Type | Details |
---|---|---|
this: date | Date | |
delta | Float | |
unit | String | One of 'year', 'month', 'week', 'day', 'hour', 'minute', or 'second'. |
timeZone | String, default: null | The time zone (e.g., 'America/Los_Angeles'); defaults to UTC. |
Examples
Code Editor (JavaScript)
// Defines a base date/time for the following examples. var BASE_DATE = ee.Date('2020-7-1T13:00', 'UTC'); print(BASE_DATE, 'The base date/time'); // Demonstrates basic usage. print(BASE_DATE.advance(1, 'week'), '+1 week'); print(BASE_DATE.advance(2, 'years'), '+2 years'); // Demonstrates that negative delta moves back in time. print(BASE_DATE.advance(-1, 'second'), '-1 second');
import ee import geemap.core as geemap
Colab (Python)
# Defines a base date/time for the following examples. BASE_DATE = ee.Date('2020-01-01T00:00', 'UTC') display('The base date/time', BASE_DATE) # Demonstrates basic usage. display('+1 week', BASE_DATE.advance(1, 'week')) display('+2 years', BASE_DATE.advance(2, 'years')) # Demonstrates that negative delta moves back in time. display('-1 second', BASE_DATE.advance(-1, 'second'))