我在使用Google Calendar API中的日期格式的datajs时遇到了问题。我相信日期时间格式是RFC3339,这是从日历api返回的示例日期时间
2012-01-05T08:45:00Z这来自datejs文档here
Date.parse('1985-04-12T23:20:50Z') // RFC 3339 Formats但这只会返回null。
我假设我的datejs工作正常,因为
Date.today().next().friday() 返回2012年5月11日星期五00:00:00 GMT+0100 (英国夏令时)
发布于 2012-05-10 18:01:55
已解决的:根据此Bug report使用Date.parseExact或this version
DEMO using date.js
DEMO using date-en-US.js
使用我得到的第一个版本
null
http://datejs.googlecode.com/files/date.js
Line 13当我将断言从testsuite中删除时
// null
console.log('Date.parse("1985-04-12T23:20:50Z")',
Date.parse('1985-04-12T23:20:50Z'));
// my previous answer works
console.log('Date.parse("1985-04-12T23:20:50Z".replace(...))',
Date.parse('1985-04-12T23:20:50Z'
.replace(/\-/g,'\/')
.replace(/[T|Z]/g,' ')
)
);
// the test suite without the Z works
console.log('1985-04-12T23:20:50',
new Date(1985,3,12,23,20,50).equals( Date.parse('1985-04-12T23:20:50')));
// but this one fails when not in the test suite
try {
console.log('1985-04-12T23:20:50Z',
new Date(1985,3,12,23,20,50).equals( Date.parse('1985-04-12T23:20:50Z')));
}
catch(e) {
console.log('1985-04-12T23:20:50Z',e.message);
}以下是不使用date.js时解决此问题的older answer
https://stackoverflow.com/questions/10531276
复制相似问题