最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why does my Date object in Google Apps Script return NaN - Stack Overflow

programmeradmin2浏览0评论

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: /

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/UTrYm/

Share Improve this question edited Oct 19, 2018 at 16:16 Wicket 38.7k9 gold badges79 silver badges194 bronze badges asked Jul 13, 2011 at 18:40 citizen conncitizen conn 15.4k3 gold badges61 silver badges80 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 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").

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);
发布评论

评论列表(0)

  1. 暂无评论