/Date(1410019200000+0800)/如何转换为date对象 javascript 时间 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /Date(1410019200000+0800)/ 是通过eval(value.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"))得到的其中的value是json序列化日期后的东西再通过一个date的扩展方法转换为人能看懂的时间字符串 s = '/Date(1410019200000+0800)/ ';s.replace(/Date\([\d+]+\)/, function(a) { eval('d = new '+a) });alert(d); <script type="text/javascript"> var date=new Date(1410019200000+0800); Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1, //month "d+" : this.getDate(), //day "h+" : this.getHours(), //hour "m+" : this.getMinutes(), //minute "s+" : this.getSeconds(), //second "q+" : Math.floor((this.getMonth()+3)/3), //quarter "S" : this.getMilliseconds() //millisecond } if(/(y+)/.test(format)) { format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); } for(var k in o) { if(new RegExp("("+ k +")").test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); } } return format; } document.write(date.format("yyyy-MM-dd hh:mm:ss")); </script>喂猫邀请我 我不认识你 var date=new Date(1410019200000+0800);document.write(date);//输出 Sun Sep 07 2014 00:00:00 GMT+0800 (中国标准时间)document.write(date.toLocaleString());//输出 2014年9月7日 上午12:00:00 参考 http://www.w3school.com.cn/jsref/jsref_toLocaleString.asp 似乎new Date(1410019200000+0800)就是我想要的答案 1410019200000是一个毫秒级的timespan,+8是时区~~ 和我的时间转换方法基本一样,我只是改成了普通方法而不是date对象的扩展方法 但是但是在执行到 "M+" : this.getMonth()+1, //month 就会报错因为传入的date对象无效 我在chrome中监视 看到是个对象而不是字符串 待转换的date对象如果像上面一样写死 这个方法可以执行成功 但是通过这种放大得到待转换的时间对象再传入方法就会报错value = eval(value.replace(/\/Date\((\d+)\)\//gi, "new Date($1)")); return TimeFormat(value, 'yyyy-MM-dd hh:mm:ss');第一句是将字符串转换成date对象 你们提供的解决方法都只是将date对象转换为制定格式字符串这下半部分 本来我也以为是下半部分的问题 但是明明按照var date=new Date(1410019200000+0800);传入是可以转换的 说明还是传入方法的date对象有问题 我也换了各个版本的jq试过都是一样的错误看来并非jq版本的问题 上面那个eval转换为date对象的方法有问题吗还是大家有其他解决办法 easyui的form提交success后返回的数据的问题,急啊。。纠结啊。。 JSP中include file的问题,求高手指点 JS面向对象语法问题 刷新另一个页面中的子页面 请教JavaScript的下拉框的问题 javascript ubb取值 如何拦截iframe子窗口内的表单提交事件? 急:请教一个下拉菜单取值问题 如何显示客户端和服务端的地址,请给出完整代码.. 请问,如何动态向select(下拉列表框)中添加项目,另外,如何取得当前的选项 js特效不出来 导入项目,部署Tomcat时报错,求解决。。
其中的value是json序列化日期后的东西
再通过一个date的扩展方法转换为人能看懂的时间字符串
s.replace(/Date\([\d+]+\)/, function(a) { eval('d = new '+a) });
alert(d);
var date=new Date(1410019200000+0800);
Date.prototype.format = function(format){
var o = {
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in o) {
if(new RegExp("("+ k +")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
}
}
return format;
}
document.write(date.format("yyyy-MM-dd hh:mm:ss"));
</script>
喂猫邀请我 我不认识你
var date=new Date(1410019200000+0800);
document.write(date);//输出 Sun Sep 07 2014 00:00:00 GMT+0800 (中国标准时间)
document.write(date.toLocaleString());//输出 2014年9月7日 上午12:00:00 参考 http://www.w3school.com.cn/jsref/jsref_toLocaleString.asp
但是在执行到 "M+" : this.getMonth()+1, //month 就会报错
因为传入的date对象无效 我在chrome中监视 看到是个对象而不是字符串
待转换的date对象如果像上面一样写死 这个方法可以执行成功 但是通过这种放大得到待转换的时间对象再传入方法就会报错value = eval(value.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
return TimeFormat(value, 'yyyy-MM-dd hh:mm:ss');第一句是将字符串转换成date对象 你们提供的解决方法都只是将date对象转换为制定格式字符串这下半部分 本来我也以为是下半部分的问题 但是明明按照var date=new Date(1410019200000+0800);传入是可以转换的 说明还是传入方法的date对象有问题 我也换了各个版本的jq试过都是一样的错误看来并非jq版本的问题 上面那个eval转换为date对象的方法有问题吗还是大家有其他解决办法