解決:使用Date.parseExact OR this version本Bug report
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);
}
以下是此問題的older answer不使用日期時。 js
您使用什麼瀏覽器和瀏覽器版本? IE7-8? Date.parse('1985-04-12T23:20:50Z')'在IE7-8中返回'NaN'。在FF中返回正確的值。 –
@AndrewD。我在Chrome –
@mplungjan中使用JavaScript控制檯,謝謝但這並沒有幫助,因爲我想使用datejs和datejs應該能夠使用1985-04-12T23:20:50Z。如果你去datejs.com,你可以在他們的網站上輸入一個日期,它會正常工作。 –