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

时间:2018-01-23 14:14:32

标签: javascript string date google-earth-engine

在Google地球引擎中,我需要从$EpisodeCounter = 1 $SeasonCounter = 1 $EpisodesPerSeason = 3 Get-ChildItem -Recurse -File | ForEach { $Season = $SeasonCounter $Episode = $EpisodeCounter++ $RootName = $_.Directory.BaseName if ($EpisodeCounter -gt $EpisodesPerSeason){ $SeasonCounter++ $EpisodeCounter = 1 } $NewName = "$($RootName) S$($Season) E$($Episode)$($_.Extension)" Rename-Item -LiteralPath $_.FullName -NewName $NewName -WhatIf } 对象生成文件名。 我在Google地球引擎中有以下代码:

ee.Date

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)

但是print(file_name)的输出是:

2017-12-01

我预计我会得到输出 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" }) 。如何在Google EarthEngine中使用带有my_file_2017-12-01对象的“+”运算符来连接两个字符串?

1 个答案:

答案 0 :(得分:2)

您看到的是代理。这在以下文档页面中进行了解释:https://developers.google.com/earth-engine/client_server。添加getInfo()可修复错误:

file_name = "my_file_" + date_string.getInfo();

https://code.earthengine.google.com/e61868ab3f333e8f2d19afd96b396964

对于服务器端的EE代码,如Nick所建议的那样:

file_name = ee.String('my_file_').cat(date_string);

https://code.earthengine.google.com/4812bb27a2869bd71771b067abd410e0