ee.Date.getInfo

从服务器检索此对象的值。

如果未提供回调函数,则以同步方式发出请求。如果提供了回调,则会异步发出请求。

建议使用异步模式,因为同步模式在等待服务器时会停止所有其他代码(例如 EE 代码编辑器界面)。如需发出异步请求,建议使用 evaluate() 而不是 getInfo()。

返回此对象的计算值。

用法返回
Date.getInfo(callback)对象
参数类型详细信息
此:computedobjectComputedObjectComputedObject 实例。
callback函数(可选)可选的回调。如果未提供,则以同步方式进行调用。

示例

代码编辑器 (JavaScript)

/**
 * WARNING: this function transfers data from Earth Engine servers to the
 * client. Doing so can negatively affect request processing and client
 * performance. Server-side options should be used whenever possible.
 * Learn more about the distinction between server and client:
 * https://developers.google.com/earth-engine/guides/client_server
 */

// A server-side ee.Date object.
var dateServer = ee.Date('2021-4-30');

// Use getInfo to transfer server-side date to the client. The result is
// an object with keys "type" and "value" where "value" is milliseconds since
// Unix epoch.
var dateClient = dateServer.getInfo();
print('Client-side date is an object', typeof dateClient);
print('Object keys include "type" and "value"', Object.keys(dateClient));
print('"value" is milliseconds since Unix epoch', dateClient.value);
print('Client-side date in JS Date constructor', new Date(dateClient.value));

Python 设置

如需了解 Python API 和如何使用 geemap 进行交互式开发,请参阅 Python 环境页面。

import ee
import geemap.core as geemap

Colab (Python)

"""
WARNING: this function transfers data from Earth Engine servers to the
client. Doing so can negatively affect request processing and client
performance. Server-side options should be used whenever possible.
Learn more about the distinction between server and client:
https://developers.google.com/earth-engine/guides/client_server
"""
from datetime import datetime

# A server-side ee.Date object.
date_server = ee.Date('2021-4-30')

# Use getInfo to transfer server-side date to the client. The result is
# a dictionary with keys "type" and "value" where "value" is milliseconds since
# Unix epoch.
date_client = date_server.getInfo()
print('Client-side date is a dictionary:', type(date_client))
print('Dictionary keys include "type" and "value":', date_client.keys())
print('"value" is milliseconds since Unix epoch:', date_client['value'])
print('Client-side date in Python:',
      datetime.fromtimestamp(date_client['value'] / 1000))