The topic is: Write a module, external call this module, request parameter is timestamp, module requirements
Today's time, unified with 24 hours writing 03:00, 15:04
Yesterday's time, unified writing yesterday
Time before yesterday, but within this week's time, unified by Monday, Tuesday, Wednesday so to write
Last week, unified collaboration 15/3/4, followed by the year/month/day
Note that the month and day are single digit, do not need to use 0 stations to become two bits, other display null
function Formattime (time) {Const __TIME = new Date (time *) function zeroize (num) {return (String (num). length = = 1? ' 0 ': ') + num} function formatTime1 () {//translates into time division seconds return ' ${zeroize (__time.gethours ())}:${zeroize (__time.getminutes ())}:${zeroize (__time.getseconds ())} '} function FormatTime2 () {//Convert to Month day return ' ${__time.getfullyear (). ToString (). s Ubstr (2,4)}/${__time.getmonth () +1}/${__time.getdate ()} '} function Getweek () {Const _DAY = new Date (time *). Get Day () switch (_day) {case 0:return ' days ' case 1:return ' one ' case 2:return ' two ' Case 3:return ' Three ' case 4:return ' four ' case 5:return ' five ' case 6:return ' six ' }} var now = ' ${new date (). getFullYear ()}/${new date (). GetMonth () +1}/${new date (). GetDate ()} 00:00:00 ' var _now = new Date (now). GetTime ()//timestamp than today at 0 O ' Day is yesterday if (time * < _now && time * > _NOW-24 * 60 * 60 * 100 0) {return ' Yesterday${formattime1 ()} '}//timestamp greater than today 0 o'clock is today if (time * > _now) {return ' Today ${formattime1 ()} '}//timestamp is less than yesterday's 0 points greater than this Monday The inter-stamp is this week if (time * < _now-24 * * * * * * * * && * * * * * * * * * * * * * * * * * * * * * * * * (new Date) ( ). GetDay ()-1) {return ' Week ${getweek ()} '}//timestamp is less than the timestamp of the previous Monday timestamp is last week if (time * < _NOW-24 * 60 * 60 * 10 XX * (new Date (). GetDay ()-1) && time * $ > _now-24 * * * * * * * * new Date (). GetDay ()-6 * 24 * 60 * * +) {return formatTime2 ()} return ' null '}
JS custom format timestamp format