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

如果想要展示时分秒,在存储时间时数据库字段应该是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;
    }