ee.Date.getRelative

Retorna a unidade especificada (baseada em 0) dessa data em relação a uma unidade maior. Por exemplo, getRelative('day', 'year') retorna um valor entre 0 e 365.

UsoRetorna
Date.getRelative(unit, inUnit, timeZone)Longo
ArgumentoTipoDetalhes
dateData
unitStringPode ser "mês", "semana", "dia", "hora", "minuto" ou "segundo".
inUnitStringPode ser "ano", "mês", "semana", "dia", "hora" ou "minuto".
timeZoneString, padrão: nullO fuso horário (por exemplo, 'America/Los_Angeles'); padrão é UTC.

Exemplos

Editor de código (JavaScript)

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'));

Configuração do Python

Consulte a página Ambiente Python para informações sobre a API Python e o uso de geemap para desenvolvimento interativo.

import ee
import geemap.core as geemap

Colab (Python)

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'))