JS-时间处理函数封装汇总 (更新中...)

刚刚看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。想看的小伙伴自己去找吧。

猜你喜欢

转载自www.cnblogs.com/padding1015/p/9389130.html
今日推荐