Google Earth Engine Date – How to Convert ee.Date Object to Client String in GEE

dategoogle-earth-engine

I'm trying to export all the images in an ImageCollection to Google Drive and by default name the output image with the date using format() function. However, when I try to name a export task by a date, the name in tasks is something like:

ee.String({ "type": "Invocation", "arguments": { "date": { "type": "Invocation", "arguments": { "value": { "type": "Invocation", "arguments": { "object": { "type": "ArgumentRef", "value": "_MAPPING_VAR_0_0" }, "property": "system:time_start" }, "functionName": "Element.get" } }, "functionName": "Date" }, "format": "YYYY-MM-DD" }, "functionName": "Date.format" })

Note the date values are gone and only some of the images are exported. Here's the link to the code

All I need is only a formatted string from a date object.

Is there a simpler way to export an image collection?

Best Answer

As @Kersten commented, you should use a client side loop

var size = S2VI.size().getInfo()
var S2VI_list = S2VI.toList(size)

for (var n=0; n<size; n++) {
  var image = ee.Image(S2VI_list.get(n))
  var date = ee.Date(image.get('system:time_start')).format('YYYY-MM-DD');
  date = date.getInfo();
  Export.image.toDrive({
    image: image,
    description: date,
    fileNamePrefix: date, // this is the name actually
    folder: 'EE Outputs',
    scale: 20,
    region: XiangJiang,
    maxPixels: 130000000000,
  })
};
Related Question