ee.Date.getRelative

指定された(0 ベースの)単位を、より大きな単位に対して相対的に返します。たとえば、getRelative('day', 'year') は 0 ~ 365 の値を返します。

用途戻り値
Date.getRelative(unit, inUnit, timeZone)Long
引数タイプ詳細
this: date日付
unit文字列「month」、「week」、「day」、「hour」、「minute」、「second」のいずれか。
inUnit文字列「year」、「month」、「week」、「day」、「hour」、「minute」のいずれか。
timeZone文字列、デフォルト: nullタイムゾーン(例: 'America/Los_Angeles')。デフォルトは UTC です。

コードエディタ(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'));

Python の設定

Python API とインタラクティブな開発での geemap の使用については、 Python 環境のページをご覧ください。

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