在网上搜到一个 其中有个函数好像有点问题 不知道怎么改
function jsonDateParser(key, value) {
if (typeof value === 'string' ) {
var a = (/^/\/Date\((\d+)([\+\-](\d\d)(\d\d))?\)//gi).exec(value);
if (a) {
var utcMilliseconds = parseInt(a[1], 10) + ((a[3] == '-') ? -1 : 1) * (parseInt(a[4], 10) + (parseInt(a[5], 10) / 60.0)) * 60 * 60 * 1000;
return new Date(utcMilliseconds);
}
}
return value;
}
就是第三行那里 两个//变成注释了
function jsonDateParser(key, value) {
if (typeof value === 'string' ) {
var a = (/^/\/Date\((\d+)([\+\-](\d\d)(\d\d))?\)//gi).exec(value);
if (a) {
var utcMilliseconds = parseInt(a[1], 10) + ((a[3] == '-') ? -1 : 1) * (parseInt(a[4], 10) + (parseInt(a[5], 10) / 60.0)) * 60 * 60 * 1000;
return new Date(utcMilliseconds);
}
}
return value;
}
就是第三行那里 两个//变成注释了
<!--
alert(new Date(1278903921551+0800)) //-->
</script>
<!--
alert(jsonDateParser("","/Date(1278903921551+0800)/"))
function jsonDateParser(key, value) {
if (typeof value === 'string' ) {
var a = (/^\/Date\((\d+)(([\+\-])(\d\d)(\d\d))?\)/gi).exec(value);
if (a) {
var utcMilliseconds = parseInt(a[1], 10) + ((a[3] == '-') ? -1 : 1) * (parseInt(a[4], 10) + (parseInt(a[5], 10) / 60.0)) * 60 * 60 * 1000;
return new Date(utcMilliseconds);
}
}
return value;
} //-->
</script>
function jsonDateParser(key, value) {
if (typeof value === 'string' ) {
if (/\/Date\((\d+)(?:([+-])(\d\d)(\d\d))?\)\//ig.test(value)) {
var d = new Date(parseInt(RegExp.$1, 10));
if (!!RegExp.$3) {
d.setHours(d.getHours() + parseInt(RegExp.$2+RegExp.$3, 10));
}
if (!!RegExp.$4) {
d.setMinutes(d.getMinutes() + parseInt(RegExp.$2+RegExp.$4, 10));
}
return d;
}
}
return value;
}
里面就是一个,Date.Parse 值