formatMessageTime: function (time) { var week = { "0": "星期日", "1": "星期一", "2": "星期二", "3": "星期三", "4": "星期四", "5": "星期五", "6": "星期六" }; var oneDay = 24 * 60 * 60 * 1000, oneWeek = 6 * 24 * 60 * 60 * 1000, oneYear = 365 * 24 * 60 * 60 * 1000; // return function (time) { if (!time) { return ''; } if (typeof (time) === 'string') { return time; } var sendTime = new Date(time), currentTime = new Date(); var yesterdayTime = new Date(currentTime.getFullYear(), currentTime.getMonth(), currentTime.getDate()); var minutes = sendTime.getMinutes(); var hours = sendTime.getHours(); minutes = minutes > 9 ? minutes : '0' + minutes; hours = hours > 9 ? hours : '0' + hours; var showSendTime = hours + ':' + minutes; var showDate; // 今天 if (sendTime >= yesterdayTime) { return showSendTime; } // 昨天 else if (sendTime >= yesterdayTime - oneDay) { showDate = '昨天'; } // 一周内 else if (sendTime >= yesterdayTime - oneWeek) { showDate = week[sendTime.getDay().toString()]; } // 今年内 else if (sendTime.getFullYear() == currentTime.getFullYear()) { showDate = (sendTime.getMonth() + 1) + '/' + sendTime.getDate(); } // 本世纪 else if (sendTime.getFullYear().toString().slice(0, 2) == currentTime.getFullYear().toString().slice(0, 2)) { showDate = sendTime.getFullYear().toString().slice(2) + '/' + (sendTime.getMonth() + 1) + '/' + sendTime.getDate(); } // else { showDate = sendTime.getFullYear() + '/' + (sendTime.getMonth() + 1) + '/' + sendTime.getDate(); } return showDate + ' ' + showSendTime; // }; }, formatTime: function (time) { var d = new Date(time); var year = d.getFullYear(); var month = d.getMonth() + 1; var day = d.getDate() < 10 ? '0' + d.getDate() : '' + d.getDate(); var hour = d.getHours(); var minutes = d.getMinutes(); var seconds = d.getSeconds(); // return year + '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds; return hour + ':' + minutes; }, formatYMDhmsTime: function (time) { var d = new Date(time); var year = d.getFullYear(); var month = d.getMonth() + 1; var day = d.getDate() < 10 ? '0' + d.getDate() : '' + d.getDate(); var hour = d.getHours(); var minutes = d.getMinutes(); var seconds = d.getSeconds(); return year + '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds; // return hour + ':' + minutes; }, formatYMDhmTime: function (time) { var d = new Date(time); var year = d.getFullYear(); var month = d.getMonth() + 1; var day = d.getDate() < 10 ? '0' + d.getDate() : '' + d.getDate(); var hour = d.getHours(); var minutes = d.getMinutes() <10 ? '0' + d.getMinutes() : '' + d.getMinutes(); var seconds = d.getSeconds(); return year + '-' + month + '-' + day + ' ' + hour + ':' + minutes; // return hour + ':' + minutes; },