json 返回数据时间的绑定的转换
function ChangeDateFormat(dateTime) {
var date = new Date(parseInt(dateTime.replace("/Date(", "").replace(")/", ""), 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 min = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
// var sec = date.getSeconds()<10?"0"+date.getSeconds():date.getSeconds();
//return date.getFullYear() + "-" + month + "-" + currentDate + " " +hour+":"+min+":"+sec;
return date.getFullYear() + "-" + month + "-" + currentDate + " " + hour + ":" + min;
}
直接调用就行!
function GetDateDiff(dateTime) {
var minute = 1000 * 60;
var hour = minute * 60;
var day = hour * 24;
var month = day * 30;
var tempTime = dateTime ? Date.parse(dateTime.replace(/-/gi, "/")) : new Date().getTime();
var now = new Date().getTime();
var diffValue = now - tempTime;
var monthTemp = diffValue / month;
var weekTemp= diffValue / (7 * day);
var dayTemp = diffValue / day;
var hourTemp = diffValue / hour;
var minTemp = diffValue / minute;
if (monthTemp >= 1) {
return dateTime;
}
else if (weekTemp >= 1) {
result = "" + parseInt(weekTemp) + " 个星期前";
}
else if (dayTemp >= 1) {
result = "" + parseInt(dayTemp) + " 天前";
}
else if (hourTemp >= 1) {
result = "" + parseInt(hourTemp) + " 个小时前";
}
else if (minTemp >= 1) {
result = "" + parseInt(minTemp) + " 分钟前";
} else
result = "刚刚发表";
return result;
}