ee.Date.advance
Create a new Date by adding the specified units to the given Date.
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
// 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');
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
# 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'))
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-13 UTC.
[null,null,["Last updated 2024-07-13 UTC."],[[["`Date.advance()` creates a new Date object by adding a specified amount of time to an existing Date."],["The time units for advancement can be 'year', 'month', 'week', 'day', 'hour', 'minute', or 'second'."],["A positive `delta` argument moves the date forward in time, while a negative `delta` moves it backward."],["The optional `timeZone` argument specifies the time zone for the calculation; it defaults to UTC if not provided."]]],["The `Date.advance` function modifies a given date by adding a specified `delta` of time units. Units can be 'year', 'month', 'week', 'day', 'hour', 'minute', or 'second'. A negative `delta` subtracts time. An optional `timeZone` argument sets the time zone. It takes a date object, a float for `delta` and string for `unit` as arguments. The function returns a new Date object with modified time.\n"]]