ee.Date

建構新的 Date 物件。

用量傳回
ee.Date(date, tz)日期
引數類型詳細資料
dateComputedObject|Date|Number|String要轉換的日期,可以是下列其中一種:數字 (自 Epoch 紀元以來的毫秒數)、ISO 日期字串、JavaScript 日期或 ComputedObject。
tz字串 (選用)選填時區,僅適用於字串日期。

範例

程式碼編輯器 (JavaScript)

// Numeric inputs are interpreted as milliseconds from Unix epoch.
print(ee.Date(0));  // Date (1970-01-01 00:00:00)

// Scale factors can make numerical inputs more readable (e.g. 60 seconds).
print(ee.Date(60 * 1000));  // Date (1970-01-01 00:01:00)

// ISO 8601 date string input examples.
print(ee.Date('2020'));  // Date (2020-01-01 00:00:00)
print(ee.Date('2017-6-24'));  // Date (2017-06-24 00:00:00)
print(ee.Date('2017-06-24'));  // Date (2017-06-24 00:00:00)
print(ee.Date('2017-6-24T00:14:46'));  // Date (2017-06-24 00:14:46)
print(ee.Date('2017-06-24T23:59:59'));  // Date (2017-06-24 23:59:59)

// With an optional time zone.
print(ee.Date('2020', 'US/Mountain'));  // Date (2020-01-01T07:00:00)

// Convert JavaScript now to Earth Engine Date
print(ee.Date(Date.now()));

Python 設定

請參閱 Python 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

import ee
import geemap.core as geemap

Colab (Python)

from datetime import datetime

# Numeric inputs are interpreted as milliseconds from Unix epoch.
print(ee.Date(0).format().getInfo())  # 1970-01-01T00:00:00

# Scale factors can make numerical inputs more readable (e.g. 60 seconds).
print(ee.Date(60 * 1000).format().getInfo())  # 1970-01-01T00:01:00

# ISO 8601 date string input examples.
print(ee.Date('2020').format().getInfo())  # 2020-01-01T00:00:00
print(ee.Date('2017-6-24').format().getInfo())  # 2017-06-24T00:00:00
print(ee.Date('2017-06-24').format().getInfo())  # 2017-06-24T00:00:00
print(ee.Date('2017-6-24T00:14:46').format().getInfo())  # 2017-06-24T00:14:46
print(ee.Date('2017-06-24T23:59:59').format().getInfo())  # 2017-06-24T23:59:59

# With an optional time zone.
print(ee.Date('2020', 'US/Mountain').format().getInfo())  # 2020-01-01T07:00:00

# Convert Python datetime.now() to Earth Engine Date
print(ee.Date(datetime.now()).format().getInfo())