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?
Asked
Active
Viewed 1,382 times
0

Yusuf Bhabhrawala
- 107
- 9
-
Does simply doing `new Date()` work? Trying to see if it is a parameter issue or an issue with the script maybe handling `Date` differently. – Matthew Herbst Mar 05 '16 at 06:05
-
3Wrong format, try `new Date("2016-01-18T15:19:00Z".replace(/\-/g,'/').replace('T',' ').replace('Z',''))` – adeneo Mar 05 '16 at 06:12
-
1You need to add the milliseconds. `2016-01-18T15:19:00.000Z` – Tesseract Mar 05 '16 at 10:02
2 Answers
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