欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js 时间格式化成字符串

程序员文章站 2024-02-01 20:24: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;
        }