js 时间格式化成字符串

发布时间:2019-05-15 22:00:22发布者:Mr.Zhang阅读(232)

我用的简单的直接的字符串格式转化

        function getTimeStr() {
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var day = date.getDate();
            var hours = date.getHours();
            var minutes = date.getMinutes();
            if (month.length == 1) {
                month = "0" + month;
            }
            if (day.length == 1) {
                day = "0" + day;
            }
            if (hours.length == 1) {
                hours = "0" + hours;
            }
            if (minutes.length == 1) {
                minutes = "0" + minutes;
            }
            var d = year + "-" + month + "-" + day + " " + hours + ":" + minutes;
            return d;
        }

 





本文转自博客园,原文地址:https://www.cnblogs.com/dawenyang/p/10869071.html