Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
181 views
in Technique[技术] by (71.8m points)

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

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/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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").


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...