Mat*_*ice 4 javascript datetime date datejs
我在使用带有Google Calendar API日期格式的dataj时遇到问题.我认为日期时间格式是RFC3339,这是从日历api返回的示例日期时间
2012-01-05T08:45:00Z
Run Code Online (Sandbox Code Playgroud)
这是从datejs文件在这里
Date.parse('1985-04-12T23:20:50Z') // RFC 3339 Formats
Run Code Online (Sandbox Code Playgroud)
但这只是返回null.
我假设我有datejs正常工作
Date.today().next().friday()
Run Code Online (Sandbox Code Playgroud)
返回2012年5月11日星期五00:00:00 GMT + 0100(BST)
已解决:根据此Bug报告使用Date.parseExact或此版本
使用我得到的第一个版本
null
http://datejs.googlecode.com/files/date.js
Line 13
Run Code Online (Sandbox Code Playgroud)
当我从测试套件中取出断言时:
// 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);
}
Run Code Online (Sandbox Code Playgroud)
不使用date.js时,这是一个较旧的答案
| 归档时间: |
|
| 查看次数: |
1860 次 |
| 最近记录: |