ee.Date.getRelative

Trả về đơn vị đã chỉ định (dựa trên 0) của ngày này so với một đơn vị lớn hơn, ví dụ: getRelative('day', 'year') trả về một giá trị từ 0 đến 365.

Cách sử dụngGiá trị trả về
Date.getRelative(unit, inUnit, timeZone)Dài
Đối sốLoạiThông tin chi tiết
this: dateNgày
unitChuỗiMột trong các giá trị "tháng", "tuần", "ngày", "giờ", "phút" hoặc "giây".
inUnitChuỗiMột trong các giá trị "năm", "tháng", "tuần", "ngày", "giờ" hoặc "phút".
timeZoneChuỗi, mặc định: rỗngMúi giờ (ví dụ: 'America/Los_Angeles'); mặc định là UTC.

Ví dụ

Trình soạn thảo mã (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'));

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap cho hoạt động phát triển tương tác.

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