Utilities function in Google App Scripts not working

痴心易碎 提交于 2019-12-24 03:56:15

问题


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.


回答1:


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);
}


来源:https://stackoverflow.com/questions/20884766/utilities-function-in-google-app-scripts-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!