time-fmt.min.js
· 1000 B · JavaScript
Неформатований
const tzArr=["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"],sdArr=["夜半","鸡鸣","平旦","日出","食时","隅中","日中","日昳","晡时","日入","黄昏","人定"],sdArr2=["半夜","凌晨","黎明","清晨","早上","上午","中午","午后","下午","傍晚","晚上","深夜"];function formatTime(r){const t=new Date,o=new Date(r),e=t-o,n=Math.floor(e/1e3),u=Math.floor(n/60),f=Math.floor(u/60),a=Math.floor(f/24);if(n<60)return"刚刚";if(u<60)return`${u} 分钟前`;if(f<24)return`${f} 小时前`;if(a<7)return`${a} 天前 ${formatHour(o)}`;const $=t.getFullYear(),m=o.getFullYear();return $===m?`${o.getMonth()+1} 月 ${o.getDate()} 日 ${formatHour(o)}`:`${m} 年 ${o.getMonth()+1} 月 ${o.getDate()} 日 ${formatHour(o)}`}function formatHour(r){const t=r.getHours(),o=r.getMinutes(),e=Math.floor((t+1)/2)%12;return`${`${formatNumber(t)}:${formatNumber(o)}`} • ${tzArr[e]}时 ${sdArr[e]} (${sdArr2[e]})`}function formatNumber(r){return r<10?`0${r}`:r}
1 | const tzArr=["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"],sdArr=["夜半","鸡鸣","平旦","日出","食时","隅中","日中","日昳","晡时","日入","黄昏","人定"],sdArr2=["半夜","凌晨","黎明","清晨","早上","上午","中午","午后","下午","傍晚","晚上","深夜"];function formatTime(r){const t=new Date,o=new Date(r),e=t-o,n=Math.floor(e/1e3),u=Math.floor(n/60),f=Math.floor(u/60),a=Math.floor(f/24);if(n<60)return"刚刚";if(u<60)return`${u} 分钟前`;if(f<24)return`${f} 小时前`;if(a<7)return`${a} 天前 ${formatHour(o)}`;const $=t.getFullYear(),m=o.getFullYear();return $===m?`${o.getMonth()+1} 月 ${o.getDate()} 日 ${formatHour(o)}`:`${m} 年 ${o.getMonth()+1} 月 ${o.getDate()} 日 ${formatHour(o)}`}function formatHour(r){const t=r.getHours(),o=r.getMinutes(),e=Math.floor((t+1)/2)%12;return`${`${formatNumber(t)}:${formatNumber(o)}`} • ${tzArr[e]}时 ${sdArr[e]} (${sdArr2[e]})`}function formatNumber(r){return r<10?`0${r}`:r} |