开发过程中遇到的时间处理函数:
function parseDate(date1) {
if(utils.isBlank(date1)){
return “很久以前”;
}
date1 = new Date(Date.parse(date1.replace(/-/g,"/"))).getTime()
var date1 = new Date(date1);
var date2 = new Date();
var s1 = date1.getTime(), s2 = date2.getTime();
var total = s2 - s1;
var minutes = 1000 * 60;
var hours = minutes * 60;
var days = hours * 24;
var years = days * 365;
var m = Math.round(total / minutes);
var shi = Math.round(m / 60);
var tian = Math.round(shi / 24);
// log(m)
if (m >= 0 && m < 1) {
return “刚刚”;
} else if (m >= 1 && m < 59) {
return m + “分钟以前”;
} else if (m >= 60 && m < 1380) {
return shi + “小时以前”;
} else if (m >= 1380 && m <= 10080) {
return tian + “天以前”;
} else if (m > 10080) {
return “很久以前”
}
};
用法:parseDate(createtime);
function timeStamp(second_time){
var time = parseInt(second_time) + “秒”;
if( parseInt(second_time )> 60){
var second = parseInt(second_time) % 60;
var min = parseInt(second_time / 60);
time = min + “分” + second + “秒”;
if( min > 60 ){
min = parseInt(second_time / 60) % 60;
var hour = parseInt( parseInt(second_time / 60) /60 );
time = hour + “小时” + min + “分” + second + “秒”;
if( hour > 24 ){
hour = parseInt( parseInt(second_time / 60) /60 ) % 24;
var day = parseInt( parseInt( parseInt(second_time / 60) /60 ) / 24 );
time = day + “天” + hour + “小时” + min + “分” + second + “秒”;
}
}
}
if(parseInt(second_time)<=0){
time = “0秒”;
}
return time;
}
注意:second_time为时间戳
js各种时间处理方式
最新推荐文章于 2024-10-03 22:03:27 发布