0

new Date("2016-01-18T15:19:00Z") gives invalid date within App Script but it works perfectly fine on the console. How to parse this?

2 Answers2

1

As SpiderPig said, the problem is that the JavaScript engine used by Apps Script (Rhino) is too rigid in parsing datetime strings: it requires every component of hh:mm:ss.mmm to be present (contrary to the current ECMA standard). This is a known issue. Until it's fixed, use

new Date("2016-01-18T15:19:00.000Z") 
0

Use slashes in date instead of dashes. Here is an example:

var date = new Date ('2017/12/26 9:55 am');
Logger.log(date);
Howdy
  • 557
  • 7
  • 12