小程序根据时间转换几天前几个小时前刚刚
function timeChangeover( time ) { var result; var minute = 1000 * 60; var hour = minute * 60; var day = hour * 24; var halfamonth = day * 15; var month = day * 30; var Now = new Date().getTime(); time = time.replace(/-/g, '/'); var dateTimeStamp = Date.parse(time); var diffValue = Now - dateTimeStamp; if (diffValue < 0) { return; } var monthC = diffValue / month; var weekC = diffValue / (7 * day); var dayC = diffValue / day; var hourC = diffValue / hour; var minC = diffValue / minute; if (monthC >= 1) { if (monthC <= 12){ result = "" + parseInt(monthC) + "月前"; } else { result = "" + parseInt(monthC / 12) + "年前"; } } else if (weekC >= 1) { result = "" + parseInt(weekC) + "周前"; } else if (dayC >= 1) { result = "" + parseInt(dayC) + "天前"; } else if (hourC >= 1) { result = "" + parseInt(hourC) + "小时前"; } else if (minC >= 1) { result = "" + parseInt(minC) + "分钟前"; } else { result = "刚刚"; } return result; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。