首页 > Web开发 > 详细

JS实现页面以年月日时分秒展示时间

时间:2019-05-05 10:10:10      阅读:132      评论:0      收藏:0      [点我收藏+]

如果想要展示时分秒,在存储时间时数据库字段应该是datetime类型,mysql映射文件中应该是jdbcType="TIMESTAMP"类型

以下为JS代码

   function getMyDate(str) {
        if (str == null || str == "") {
            return ‘‘;
        }
        var oDate = new Date(str),
            oYear = oDate.getFullYear(),
            oMonth = oDate.getMonth() + 1,
            oDay = oDate.getDate(),
            oHour = oDate.getHours(),
            oMin = oDate.getMinutes(),
            oSen = oDate.getSeconds(),
            oTime = oYear + ‘-‘ + getzf(oMonth) + ‘-‘ + getzf(oDay) + ‘ ‘ + getzf(oHour) + ‘:‘ + getzf(oMin) + ‘:‘ + getzf(oSen);//最后拼接时间
        return oTime;
    };
    function getzf(num) {
        if (parseInt(num) < 10) {
            num = ‘0‘ + num;
        }
        return num;
    }

 

JS实现页面以年月日时分秒展示时间

原文:https://www.cnblogs.com/wl1202/p/10811245.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!