10

Does Google Apps Script use a funky version of EcmaScript that can't parse a date? How can I parse the date 2011-04-11T19:25:40Z into a JavaScript Date Object in Google Apps Script?

My log output from below logs NaN.

function showDate(){
  var d = Date.parse("2011-04-11T19:25:40Z");
  Logger.log(d); // <-- Logs NaN
}

Edit: http://jsfiddle.net/UTrYm/

4

2 回答 2

15

The format specified in section 15.9.1.15 is YYYY-MM-DDTHH:mm:ss.sssZ so maybe try adding milliseconds to your date format as in Date.parse("2011-04-11T19:25:40.000Z").

于 2011-07-13T18:48:40.170 回答
0

Google apps script works fine when you use slashes instead of dashes. Like:

var date = new Date ('2017/12/26 9:55 am');
Logger.log(date);
于 2017-12-27T17:36:14.740 回答