ee.Date.getFraction
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
แสดงผลเศษส่วนของหน่วยที่ระบุซึ่งผ่านไปแล้วของวันที่นี้ (ระหว่าง 0 ถึง 1)
การใช้งาน | การคืนสินค้า |
---|
Date.getFraction(unit, timeZone) | ทศนิยม |
อาร์กิวเมนต์ | ประเภท | รายละเอียด |
---|
this: date | วันที่ | |
unit | สตริง | โดยอาจเป็น "ปี", "เดือน", "สัปดาห์", "วัน", "ชั่วโมง", "นาที" หรือ "วินาที" |
timeZone | สตริง ค่าเริ่มต้น: null | เขตเวลา (เช่น 'America/Los_Angeles'); เริ่มต้นเป็น UTC |
ตัวอย่าง
เครื่องมือแก้ไขโค้ด (JavaScript)
var date = ee.Date('2021-4-30T07:15:31.24');
print('Elapsed fraction of a year', date.getFraction('year'));
print('Elapsed fraction of a month', date.getFraction('month'));
print('Elapsed fraction of a week', date.getFraction('week'));
print('Elapsed fraction of a day', date.getFraction('day'));
print('Elapsed fraction of an hour', date.getFraction('hour'));
print('Elapsed fraction of a minute', date.getFraction('minute'));
print('Elapsed fraction of a second', date.getFraction('second'));
การตั้งค่า Python
ดูข้อมูลเกี่ยวกับ Python API และการใช้ geemap
สําหรับการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า
สภาพแวดล้อม Python
import ee
import geemap.core as geemap
Colab (Python)
date = ee.Date('2021-4-30T07:15:31.24')
display('Elapsed fraction of a year:', date.getFraction('year'))
display('Elapsed fraction of a month:', date.getFraction('month'))
display('Elapsed fraction of a week:', date.getFraction('week'))
display('Elapsed fraction of a day:', date.getFraction('day'))
display('Elapsed fraction of an hour:', date.getFraction('hour'))
display('Elapsed fraction of a minute:', date.getFraction('minute'))
display('Elapsed fraction of a second:', date.getFraction('second'))
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 2025-07-25 UTC"],[[["\u003cp\u003e\u003ccode\u003eDate.getFraction()\u003c/code\u003e calculates the elapsed fraction of a specified time unit (year, month, week, day, hour, minute, or second) for a given date, returning a value between 0 and 1.\u003c/p\u003e\n"],["\u003cp\u003eThe function takes the date, the desired time unit, and an optional time zone as input (defaulting to UTC if not specified).\u003c/p\u003e\n"],["\u003cp\u003eThe returned value represents the proportion of the specified time unit that has passed for the given date, for instance, 0.5 for 'day' would indicate it's midday.\u003c/p\u003e\n"],["\u003cp\u003eThis function is valuable for tasks like determining the progress through a specific time period, such as calculating the fraction of a year that has elapsed.\u003c/p\u003e\n"]]],[],null,["# ee.Date.getFraction\n\nReturns this date's elapsed fraction of the specified unit (between 0 and 1).\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|----------------------------------------|---------|\n| Date.getFraction`(unit, `*timeZone*`)` | Float |\n\n| Argument | Type | Details |\n|--------------|-----------------------|-----------------------------------------------------------------------|\n| this: `date` | Date | |\n| `unit` | String | One of 'year', 'month', 'week', 'day', 'hour', 'minute', or 'second'. |\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('Elapsed fraction of a year', date.getFraction('year'));\nprint('Elapsed fraction of a month', date.getFraction('month'));\nprint('Elapsed fraction of a week', date.getFraction('week'));\nprint('Elapsed fraction of a day', date.getFraction('day'));\nprint('Elapsed fraction of an hour', date.getFraction('hour'));\nprint('Elapsed fraction of a minute', date.getFraction('minute'));\nprint('Elapsed fraction of a second', date.getFraction('second'));\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('Elapsed fraction of a year:', date.getFraction('year'))\ndisplay('Elapsed fraction of a month:', date.getFraction('month'))\ndisplay('Elapsed fraction of a week:', date.getFraction('week'))\ndisplay('Elapsed fraction of a day:', date.getFraction('day'))\ndisplay('Elapsed fraction of an hour:', date.getFraction('hour'))\ndisplay('Elapsed fraction of a minute:', date.getFraction('minute'))\ndisplay('Elapsed fraction of a second:', date.getFraction('second'))\n```"]]