. 1 const FormatTime = function (Tiem) { // time conversion 2 const = timestamp Date.now (); . 3 return function (Tiem) { . 4 const the diff = timestamp - Tiem * 1000 ; . 5 IF (the diff <60 * 1000 ) { . 6 return 'just' ; . 7 } the else IF (the diff <60 * 60 * 1000 ) { . 8 return Math.floor (the diff / (60 * 1000)) + 'ago' ; . 9 } the else IF (the diff <24 * 60 * 1000 * 60 ) { 10 return Math.floor(diff / (60 * 60 * 1000)) + '小时前'; 11 } else { 12 const createTime = new Date(tiem * 1000); 13 const Day = createTime.getDate(); 14 const Month = createTime.getMonth() + 1; 15 const Hour = createTime.getHours(); 16 const Minute = createTime.getMinutes(); 17 function padding(str) { 18 str = '' + str; 19 if (str[1]) { 20 return str; 21 } else { 22 return '0' + str; 23 } 24 } 25 return `${padding(Month)}-${padding(Day)} ${padding(Hour)}:${padding(Minute)}`; 26 } 27 }; 28 }