js 时间格式化成字符串

匿名 (未验证) 提交于 2019-12-02 21:53:52

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

        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;         }

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!