json时间格式转正常时间:
//传入json格式的时间
function ChangeDateFormat(jsondate) {
if (jsondate==null || jsondate=="") {
return "";
}
try {
jsondate = jsondate.replace("/Date(", "").replace(")/", "");
} catch (e) {
jsondate=jsondate.time;
jsondate=jsondate+"";
}
if (jsondate.indexOf("+") > 0) {
jsondate = jsondate.substring(0, jsondate.indexOf("+"));
}
else if (jsondate.indexOf("-") > 0) {
jsondate = jsondate.substring(0, jsondate.indexOf("-"));
}
var date = new Date(parseInt(jsondate, 10));
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var branch = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
return date.getFullYear()
+ "-"
+ month
+ "-"
+ currentDate
+ " "
+ hour
+ ":"
+ branch
+ ":"
+ second;
}
时间戳转正常时间:
function formatDate(now) {
var year=now.getFullYear();
var month=now.getMonth()+1;
var date=now.getDate();
var hour=now.getHours();
var minute=now.getMinutes();
var second=now.getSeconds();
return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;
}
//如果记得时间戳是毫秒级的就需要*1000 不然就错了记得转换成整型
var d=new Date(1230999938);
alert(formatDate(d));