0

I am attempting to add a month identifier ('03', '04', etc.) to a list of years in Google Earth Engine.

var year = ee.List.sequence(1992, 2021, 1).map(function(number){return ee.Number(number)}) print('Year', year) var test = year.map(function(year){ var marKey = ee.String(year).cat('3') return marKey }); print('Test', test) 

However, when I run this script, the list of elements that are returned are in this format:

1992.03, 1993.03, 1994.03, etc.

And I want these to appear like this:

199203, 199303, 199403, etc.

I'm writing a larger function to select images from an ImageCollection and the incorrect format of the year-month is not allowing my function to select the appropriate images.

1 Answer 1

0

Use the ee.Number.format function to control decimal places and padding with printf-style formatting specifications. Here, we say we want no decimal place on the year, and zero-fill the month to length 2.

var year = ee.List.sequence(1992, 2021, 1) print('Year', year) var test = year.map(function(year){ var marKey = ee.Number(year).format('%.0f').cat(ee.Number(3).format('%02d')) return marKey }); print('Test', test) 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.