Question

Function Utilities.formatDate in Google App Scripts is not working correct for date in year 2013

Example-

date = Tue Dec 31 2013 18:43:12 GMT+0530 (IST)

after formatting it in YYYYMMdd format

using code-

Utilities.formatDate(date, "IST" ,"YYYYMMdd"))

result was- 20**14**1231

In the above result year is expected to be 2013 as per above mentioned date.

The same code is working correct for date in 2012 and 2014.

Était-ce utile?

La solution

Just change your pattern from YYYY to yyyy (lower case) and it will work, check this:

function myFunction() {
  var date = new Date("Tue Dec 31 2013 18:43:12 GMT+0530 (IST)");

//after formatting it in YYYYMMdd format
  var format = Utilities.formatDate(date,"IST", "yyyyMMdd");

  Logger.log(format);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top