使用datejs解析RFC3339 datetime的Javascript

使用datejs解析RFC3339 datetime的Javascript,javascript,datetime,date,datejs,Javascript,Datetime,Date,Datejs,我在使用带有Google日历API中日期格式的datajs时遇到问题。我认为datetime格式是RFC3339,这是从CalendarAPI返回的datetime示例 2012-01-05T08:45:00Z 这来自datejs文档 但这只是返回null 我假设datejs可以正常工作 Date.today().next().friday() 返回2012年5月11日星期五00:00:00 GMT+0100(英国夏令时)已解决:使用Date.parseExact或根据此 使用我得到

我在使用带有Google日历API中日期格式的datajs时遇到问题。我认为datetime格式是RFC3339,这是从CalendarAPI返回的datetime示例

2012-01-05T08:45:00Z
这来自datejs文档

但这只是返回null

我假设datejs可以正常工作

Date.today().next().friday() 

返回2012年5月11日星期五00:00:00 GMT+0100(英国夏令时)

已解决:使用Date.parseExact或根据此


使用我得到的第一个版本

null
http://datejs.googlecode.com/files/date.js
Line 13
当我将断言从中取出时:


在不使用date.js时,这里有一个解决此问题的方法,您使用的浏览器和浏览器版本是什么?IE7-8<代码>日期.解析('1985-04-12T23:20:50Z')返回IE7-8中的
NaN
。在FF中返回了正确的值。@AndrewD。我正在使用中的JavaScript控制台Chrome@mplungjan谢谢,但这没有帮助,因为我想使用datejs,datejs应该可以使用1985-04-12T23:20:50Z。如果你去datejs.com,你可以在他们的网站上输入一个日期,它会工作得很好。似乎date.parseExact(“1985-04-12T23:20:50Z”,“yyyy-MM-ddTHH:MM:ssZ”)可以正常工作。根据它与date.parseExact(“1985-04-12T23:20:50Z”,“yyyy-MM-ddTHH:MM:ssZ”)的速度要快得多,那么要么使用上面的版本,要么使用parseExact。我不认为速度是这里的问题。
null
http://datejs.googlecode.com/files/date.js
Line 13
// 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);
}