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'))
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 2025-07-25 UTC"],[[["\u003cp\u003e\u003ccode\u003eDate.getRelative()\u003c/code\u003e returns the 0-based position of a specified time unit (e.g., day, month) within a larger time unit (e.g., year, month).\u003c/p\u003e\n"],["\u003cp\u003eThe function takes 'unit', 'inUnit', and an optional 'timeZone' as arguments to define the relative position and time zone context.\u003c/p\u003e\n"],["\u003cp\u003eValid units include 'year', 'month', 'week', 'day', 'hour', 'minute', and 'second'.\u003c/p\u003e\n"],["\u003cp\u003eIf the 'unit' is larger than the 'inUnit', the function returns 0.\u003c/p\u003e\n"]]],[],null,["# ee.Date.getRelative\n\nReturns the specified (0-based) unit of this date relative to a larger unit, e.g., getRelative('day', 'year') returns a value between 0 and 365.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|------------------------------------------------|---------|\n| Date.getRelative`(unit, inUnit, `*timeZone*`)` | Long |\n\n| Argument | Type | Details |\n|--------------|-----------------------|---------------------------------------------------------------|\n| this: `date` | Date | |\n| `unit` | String | One of 'month', 'week', 'day', 'hour', 'minute', or 'second'. |\n| `inUnit` | String | One of 'year', 'month', 'week', 'day', 'hour', or 'minute'. |\n| `timeZone` | String, default: null | The time zone (e.g., 'America/Los_Angeles'); defaults to UTC. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\nvar date = ee.Date('2021-4-30T07:15:31.24');\n\nprint('0-based month of year', date.getRelative('month', 'year'));\nprint('0-based week of year', date.getRelative('week', 'year'));\nprint('0-based day of year', date.getRelative('day', 'year'));\nprint('0-based day of month', date.getRelative('day', 'month'));\nprint('0-based minute of day', date.getRelative('minute', 'day'));\nprint('0-based second of minute', date.getRelative('second', 'minute'));\n\n// 0 is returned when unit argument is larger than inUnit argument.\nprint('0-based year of month (bad form)', date.getRelative('year', 'month'));\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\ndate = ee.Date('2021-4-30T07:15:31.24')\n\ndisplay('0-based month of year:', date.getRelative('month', 'year'))\ndisplay('0-based week of year:', date.getRelative('week', 'year'))\ndisplay('0-based day of year:', date.getRelative('day', 'year'))\ndisplay('0-based day of month:', date.getRelative('day', 'month'))\ndisplay('0-based minute of day:', date.getRelative('minute', 'day'))\ndisplay('0-based second of minute:', date.getRelative('second', 'minute'))\n\n# 0 is returned when unit argument is larger than inUnit argument.\ndisplay('0-based year of month (bad form):', date.getRelative('year', 'month'))\n```"]]