如何使用“+”运算符将两个字符串连接起来?

3
在Google Earth Engine中,我需要从ee.Date对象生成文件名。 我在Google Earth Engine中有以下代码:
var date_object = ee.Date.fromYMD(2017,12, 1);
var date_string = date_object.format("YYYY-MM-dd");
print(date_string);
file_name = "my_file_" + date_string;
print(file_name);

print(date_string) 的输出看起来不错:

2017-12-01

但是print(file_name)的输出结果为:
    ee.String({
    "type": "Invocation",
    "arguments": {
        "date": {
          "type": "Invocation",
          "arguments": {
            "year": 2017,
            "month": 12,
            "day": 1
          },
          "functionName": "Date.fromYMD"
        },
        "format": "YYYY-MM-dd"
      },
      "functionName": "Date.format"
    })

我期望得到的输出是my_file_2017-12-01。在Google EarthEngine中,如何使用"+"运算符将两个字符串连接起来?

1个回答

8

在你的例子中,最好包括 getInfo() 函数,而不是复制 OP 犯的同样的错误 :) - Adrian
2
或者,对于服务器端字符串:ee.String("my_file_").cat(date_string) - Nicholas Clinton

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接