Use ee.Image.get()
option to retrieve the specific property of interest (in your case it is system:time_start
which corresponds to the date of acquisition.)
The new loop should look something like this:
for (var i=0; i <=2; i++)
{
var image = ee.Image(listOfImages.get(i));
var label = ee.Date(image.get("system:time_start")).format('YYYY-MM-dd HH:mm:ss').getInfo();
Map.addLayer(image,vis_params2,label,true)
}
Explanation:
ee.Date()
function converts the acquisition times from milliseconds to date-time object.
- I have used the
.format()
option to convert the ee.Date
object
to a string but you can use any other method too.
- The
.getInfo()
is important because Map.addLayer() is a client-side function. So the label property to be passed needs to be retrieved from server-side to client-side.
Link to corrected code.