将datetime从json转换为可读格式 [英] converting datetime from json to readable format
本文介绍了将datetime从json转换为可读格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
除了其他属性DateTime属性,该属性在视图上呈现为
I'm getting besides other properties DateTime property which is rendered on the view as
/Date(1346997005000)/
我应该将此格式转换为dd.mm.yy
I should convert this to readable format as dd.mm.yy
推荐答案
var dateString = "/Date(1346997005000)/";
var dx = new Date(parseInt(dateString.substr(6)));
var dd = dx.getDate();
var mm = dx.getMonth() + 1;
var yy = dx.getFullYear();
if (dd <= 9) {
dd = "0" + dd;
}
if (mm <= 9) {
mm = "0" + mm;
}
var displayDate = dd + "." + mm + "." + yy;
使用displayDate.如果您可以访问众多JavaScript日期库之一(例如Moment.js),则应该能够将dx传递给函数并使用一行代码获取显示字符串.那将是一个更好的解决方案.
Use displayDate. If you have access to one of the numerous JavaScript date libraries (e.g. Moment.js), you should be able to just pass dx into a function and get the display string with one line of code. That'd be a nicer solution.
这篇关于将datetime从json转换为可读格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文