刚刚看maka源码看到的,哈哈赶紧记下来:
function dateFormat(e){ var t = Math.floor((new Date - new Date(e)) / 6e4); return t < 1 ? "刚刚" : t < 60 ? t + "分钟前" : t < 1440 ? Math.floor(t / 60) + "小时前" : new Date(e).getMonth() + 1 + "月" + new Date(e).getDate() + "日" } dateFormat('2018.07.30') // "10小时前"
2018-07-30 10:08:39
这不就是我一直着的时间转换嘛!而且写的还这么精致,赶紧码。
源码来源于maka官网http://maka.im/home。想看的小伙伴自己去找吧。