转换标准时间为时间戳: function getDateTimeStamp(dateStr){ return Date.parse(dateStr.replace(/-/gi,"/")); } 计算时间差: function getDateDiff(dateTimeStamp) { * ; ; ; ; ; ; var now = new Date().getTime(); var diffValue = now - dateTimeStamp; ) { return; } var ye…
背景:最近公司要做动态列表,类似于微信朋友圈.动态创建时间就需要显示为 刚刚.几分钟前.几小时前.几天前.2018-05-15,这样的形式. 代码如下 var minute = 1000 * 60; var hour = minute * 60; var day = hour * 24; // 计算时间差 handleDate(minute, hour, day,dateTimeStamp) { var result = ''; var now = new Date().getTime(); v…
function getDateDiff(dateTimeStamp){ 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(); var diffValue = now - dateTimeStamp; if(diffValue < 0){return;}…