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.
Uso | Muestra |
---|
Date.getRelative(unit, inUnit, timeZone) | Largo |
Argumento | Tipo | Detalles |
---|
esto: date | Fecha | |
unit | String | Una de las siguientes opciones: "mes", "semana", "día", "hora", "minuto" o "segundo". |
inUnit | String | Una de las siguientes opciones: "year", "month", "week", "day", "hour" o "minute". |
timeZone | Cadena, valor predeterminado: nulo | La 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'));
Configuración de Python
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'))
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
Última actualización: 2025-02-27 (UTC)
[null,null,["Última actualización: 2025-02-27 (UTC)"],[[["`Date.getRelative()` returns the 0-based position of a specified time unit (e.g., day, month) within a larger time unit (e.g., year, month)."],["The function takes 'unit', 'inUnit', and an optional 'timeZone' as arguments to define the relative position and time zone context."],["Valid units include 'year', 'month', 'week', 'day', 'hour', 'minute', and 'second'."],["If the 'unit' is larger than the 'inUnit', the function returns 0."]]],[]]