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 设置
如需了解 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'))
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-02-27。
[null,null,["最后更新时间 (UTC):2025-02-27。"],[[["`Date.getRelative()` returns the 0-based position of a specified time unit (e.g., day, month) within a larger time unit (e.g., year, month)."],["The function takes 'unit', 'inUnit', and an optional 'timeZone' as arguments to define the relative position and time zone context."],["Valid units include 'year', 'month', 'week', 'day', 'hour', 'minute', and 'second'."],["If the 'unit' is larger than the 'inUnit', the function returns 0."]]],[]]