ee.Date.getRelative

แสดงผลหน่วยที่ระบุ (ฐาน 0) ของวันที่นี้เทียบกับหน่วยที่ใหญ่กว่า เช่น getRelative('day', 'year') จะแสดงผลค่าระหว่าง 0 ถึง 365

การใช้งานการคืนสินค้า
Date.getRelative(unit, inUnit, timeZone)ยาว
อาร์กิวเมนต์ประเภทรายละเอียด
this: dateวันที่
unitสตริงโดยอาจเป็น "เดือน", "สัปดาห์", "วัน", "ชั่วโมง", "นาที" หรือ "วินาที"
inUnitสตริงโดยอาจเป็น "ปี", "เดือน", "สัปดาห์", "วัน", "ชั่วโมง" หรือ "นาที"
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'))