zoukankan      html  css  js  c++  java
  • 时间戳格式转换

    时间戳转换格式为年月日星期几

    /**
     *[formatDate 转换事件格式并返回html片段]
     * author: LiuWei
     * time: 2017/9/19
     * @param  {[type]} timestamp [时间戳]
     * @return {[type]}           [时间html片段]
     */
    function formatDate(timestamp) {
        var dateObj = new Date(timestamp);
        var theYear = dateObj.getFullYear();
        var theMonth = dateObj.getMonth();
        var theDay = dateObj.getDate();
        var theWeekDay = dateObj.getDay();
        var theHour = dateObj.getHours();
        var theMinute = dateObj.getMinutes();
        switch (theWeekDay) {
            case 0:
                theWeekDay = '周日';
                break;
            case 1:
                theWeekDay = '周一';
                break;
            case 2:
                theWeekDay = '周二';
                break;
            case 3:
                theWeekDay = '周三';
                break;
            case 4:
                theWeekDay = '周四';
                break;
            case 5:
                theWeekDay = '周五';
                break;
            case 6:
                theWeekDay = '周六';
                break;
        }
        console.log(theWeekDay);
        var dateHtml = '<span class="day">' + theYear + '.' +
            (theMonth + 1 < 10 ? '0' + (theMonth + 1) : (theMonth + 1)) + '.' +
            (theDay < 10 ? '0' + theDay : theDay) + '</span>' +
            '<span class="week">' + (theWeekDay < 10 ? '0' + theWeekDay : theWeekDay) + '</span>' +
            '<span class="time">' + (theHour < 10 ? '0' + theHour : theHour) + ':' + (theMinute < 10 ? '0' + theMinute : theMinute) + '</span>';
        console.log(dateHtml);
        return dateHtml;
    }
  • 相关阅读:
    关于缓存雪崩穿透击穿等一些问题
    MethodHandler笔记
    并发总结(博客转载)
    负载均衡的几种算法Java实现代码
    SpringJdbc插入对象返回主键的值
    【Java基础】01-推荐参考材料
    【Java基础】注解
    【JSON】
    【Kafka】3-配置文件说明
    【Kafka】1-理论知识
  • 原文地址:https://www.cnblogs.com/lw5116/p/7791920.html
Copyright © 2011-2022 走看看