ee.Date.getRelative

返回此日期相对于较大单位的指定(从 0 开始)单位,例如,getRelative('day', 'year') 会返回一个介于 0 和 365 之间的值。

用法返回
Date.getRelative(unit, inUnit, timeZone)
参数类型详细信息
this:date日期
unit字符串可以选择“月”“周”“天”“小时”“分钟”或“秒”。
inUnit字符串可以选择“年”“月”“周”“日”“小时”或“分钟”。
timeZone字符串,默认值:null时区(例如,'America/Los_Angeles');默认为世界协调时间 (UTC)。

示例

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 API 以及如何使用 geemap 进行交互式开发,请参阅 Python 环境页面。

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