公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取 Earth Engine。
ee.Date.getFraction
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
傳回此日期與指定單位 (介於 0 和 1 之間) 的已過時間。
用量 | 傳回 |
---|
Date.getFraction(unit, timeZone) | 浮點值 |
引數 | 類型 | 詳細資料 |
---|
this:date | 日期 | |
unit | 字串 | 可以是「year」、「month」、「week」、「day」、「hour」、「minute」或「second」。 |
timeZone | 字串,預設值:空值 | 時區 (例如'America/Los_Angeles');預設為世界標準時間。 |
範例
程式碼編輯器 (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 環境」頁面,瞭解 Python API 和如何使用 geemap
進行互動式開發。
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'))
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[[["\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```"]]