为什么我在 Google Apps Script 中的 Date 对象返回 NaN [英] Why does my Date object in Google Apps Script return NaN
本文介绍了为什么我在 Google Apps Script 中的 Date 对象返回 NaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Google Apps Script 是否使用无法解析日期的时髦版本的 EcmaScript?如何将日期 2011-04-11T19:25:40Z
解析为 Google Apps 脚本中的 JavaScript 日期对象?
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?
我从下面的日志输出NaN
.
function showDate(){
var d = Date.parse("2011-04-11T19:25:40Z");
Logger.log(d); // <-- Logs NaN
}
推荐答案
15.9.1.15 是 YYYY-MM-DDTHH:mm:ss.sssZ
所以也许尝试在你的日期格式中添加毫秒Date.parse("2011-04-11T19:25:40.000Z")
.
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 中的 Date 对象返回 NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文