ee.Date.getRelative

傳回此日期相對於較大單位的指定 (以 0 為基底) 單位,例如 getRelative('day', 'year') 會傳回介於 0 和 365 之間的值。

用量傳回
Date.getRelative(unit, inUnit, timeZone)
引數類型詳細資料
this:date日期
unit字串可以是「month」、「week」、「day」、「hour」、「minute」或「second」。
inUnit字串可以是「year」、「month」、「week」、「day」、「hour」或「minute」。
timeZone字串,預設值:空值時區 (例如'America/Los_Angeles');預設為世界標準時間。

範例

程式碼編輯器 (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 環境」頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

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