js 将日期转为多少分钟前

来源:互联网 发布:好用的吹风机知乎 编辑:程序博客网 时间:2024/04/27 05:23
                     //当前的日期    要转换日期function Dateformat(CurrentDateStr, SourceDateStr) {    try {        var CurrentDate = new Date(CurrentDateStr);        var SourceDate = new Date(SourceDateStr);        //毫秒        var span = CurrentDate - SourceDate;        //秒        var seconds = parseInt(span / 1000);        //分钟        var minutes = parseInt(seconds / 60);        //小时        var hours = parseInt(minutes / 60);        //天        var Day = parseInt(hours / 24);        if (Day > 60) {            return SourceDate.getMonth() + "月" + SourceDate.getDay() + "号";        }        else if (Day > 30) {            return "1个月前";        }        else if (Day > 28) {            return "4周前";        }        else if (Day > 21) {            return "3周前";        }        else if (Day > 14) {            return "2周前";        }        else if (Day > 7) {            return "1周前";        }        else if (Day > 1) {            return format("{0}天前", Day);        }        else if (hours > 1) {            return format("{0}小时前", hours);        }        else if (minutes > 1) {            return format("{0}分钟前", minutes);        }        else if (seconds >= 1) {            return format("{0}秒前", seconds);        }        else {            return "1秒前";        }    } catch (e) {        return "";    }}
0 0
原创粉丝点击