问题
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