ee.Date.getRelative

Devuelve la unidad especificada (basada en 0) de esta fecha en relación con una unidad más grande; p.ej., getRelative('day', 'year') muestra un valor entre 0 y 365.

UsoMuestra
Date.getRelative(unit, inUnit, timeZone)Largo
ArgumentoTipoDetalles
esto: dateFecha
unitStringUna de las siguientes opciones: "mes", "semana", "día", "hora", "minuto" o "segundo".
inUnitStringUna de las siguientes opciones: "year", "month", "week", "day", "hour" o "minute".
timeZoneCadena, valor predeterminado: nuloLa zona horaria (p.ej., 'America/Los_Angeles'); la configuración predeterminada es UTC.

Ejemplos

var date = ee.Date('2021-4-30T07:15:31.24');

print('0-based month of year', date.getRelative('month', 'year'));
print('0-based week of year', date.getRelative('week', 'year'));
print('0-based day of year', date.getRelative('day', 'year'));
print('0-based day of month', date.getRelative('day', 'month'));
print('0-based minute of day', date.getRelative('minute', 'day'));
print('0-based second of minute', date.getRelative('second', 'minute'));

// 0 is returned when unit argument is larger than inUnit argument.
print('0-based year of month (bad form)', date.getRelative('year', 'month'));

Consulta la página Entorno de Python para obtener información sobre la API de Python y el uso de geemap para el desarrollo interactivo.

import ee
import geemap.core as geemap
date = ee.Date('2021-4-30T07:15:31.24')

display('0-based month of year:', date.getRelative('month', 'year'))
display('0-based week of year:', date.getRelative('week', 'year'))
display('0-based day of year:', date.getRelative('day', 'year'))
display('0-based day of month:', date.getRelative('day', 'month'))
display('0-based minute of day:', date.getRelative('minute', 'day'))
display('0-based second of minute:', date.getRelative('second', 'minute'))

# 0 is returned when unit argument is larger than inUnit argument.
display('0-based year of month (bad form):', date.getRelative('year', 'month'))