ee.Date.getRelative

Zwraca określoną jednostkę (zliczaną od 0) tej daty w stosunku do większej jednostki, np. getRelative(„day”, „year”) zwraca wartość od 0 do 365.

WykorzystanieZwroty
Date.getRelative(unit, inUnit, timeZone)Długie
ArgumentTypSzczegóły
to: dateData
unitCiąg znakówJedna z wartości „month” (miesiąc), „week” (tydzień), „day” (dzień), „hour” (godzina), „minute” (minut) lub „second” (sekunda).
inUnitCiąg znakówJedna z wartości „year” (rok), „month” (miesiąc), „week” (tydzień), „day” (dzień), „hour” (godzina) lub „minute” ( minuta).
timeZoneCiąg tekstowy, domyślnie: nullStrefa czasowa (np. 'America/Los_Angeles'); domyślnie ustawiona jest strefa czasowa UTC.

Przykłady

Edytor kodu (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'));

Konfiguracja Pythona

Informacje o interfejsie Python API i o używaniu pakietu geemap do programowania interaktywnego znajdziesz na stronie Python Environment.

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