Converting a string timestamp to Date results in reset to UNIX epoch

With moment.js, it is as easy as this to parse any of ISO 8601 format.

var date = Moment.moment("2013-01-17T17:34:50.507").toDate();

You can use moment.js to parse your arbitrary date string as well.

To use moment.js in GAS, you just need to add it in the script editor. Open your script in GAS script editor and go to "Resources" then "Libraries...", then put this project key MHMchiX6c1bwSqGM1PZiW_PxhMjh3Sh48 and click "Add". Choose the version from the dropdown, then click "Save". Now, you are ready to use moment.js in GAS.

moment.js can be used to parse date string, create formatted date string, and many other date manipulation. Thanks to the author!

You can find the moment.js documentation here.


It doesn't work in GScript, at least for me at the time I'm writing it. This post serves a working alternative: How do I format this date string so that google scripts recognizes it?


It doesn't appear that the Date object knows how to handle that date. The date is in ISO 8601 format. Javascript can handle Dates if they are given timezone information.

You will have to do some testing, but if those dates given to you are in UTC time, then just add a Z to the end of the date string before you call new Date().

Edit: The Apps Script Date object can't seem to handle a timezone other than UTC when parsing a Date. I opened an issue for it.