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
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');
Colab (Python)
"""Demonstrates the ee.Date.advance method."""
import ee
# Authenticates to the Earth Engine servers.
ee.Authenticate()
# Initializes the client library.
ee.Initialize()
def print_date(ee_date, message):
"""Prints a formatted date, along with a descriptive message."""
print(ee_date.format().getInfo(), message)
# Defines a base date/time for the following examples.
BASE_DATE = ee.Date('2020-01-01T00:00', 'UTC')
print_date(BASE_DATE, 'The base date/time')
# Demonstrates basic usage.
print_date(BASE_DATE.advance(1, 'week'), '+1 week')
print_date(BASE_DATE.advance(2, 'years'), '+2 years')
# Demonstrates that negative delta moves back in time.
print_date(BASE_DATE.advance(-1, 'second'), '-1 second')