alert(JSON.stringify(obj, null, 2));
将对象转换为string
alert(JSON.stringify(JSON.parse(str), null, 2));
将字符串转换为json对象, 再转换为string
毫秒时间格式化输出
var date = new Date(timeval * 1000);
return date.format("yyyy年MM月dd日 hh时mm分ss秒 星期W");
Date.prototype.format = function(format) {
var date = this;
var o =
{
"M+" : date.getMonth()+1, //month
"d+" : date.getDate(), //day
"h+" : date.getHours(), //hour
"m+" : date.getMinutes(), //minute
"s+" : date.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : date.getMilliseconds(), //millisecond
"W": function () {
var week;
switch ( date.getDay()) {
case 0: week = "日"; break;
case 1: week = "一"; break;
case 2: week = "二"; break;
case 3: week = "三"; break;
case 4: week = "四"; break;
case 5: week = "五"; break;
case 6: week = "六"; break;
}
return week;
}
}
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;
};