首页 > Web开发 > 详细

js获取当前时间

时间:2018-05-28 22:26:41      阅读:178      评论:0      收藏:0      [点我收藏+]
/**
     * getNowFormatDate 获取当前时间
     * @param msec 毫秒值
     */
    getNowFormatDate :function(msecVal){
        if(msecVal){
            var now = new Date(msecVal); //毫秒值转为完整时间
        }else{
            var now = new Date(); //完整时间
        };
        var month = now.getMonth() + 1; //当前月份
        var day = now.getDate();        //当前天
        var Hours = now.getHours();     //当前时
        var Minutes = now.getMinutes(); //当前分
        var Seconds = now.getSeconds(); //当前秒
        if(month >= 1 && month <= 9){   //
            month = "0" + month;
        };
        if(day >= 0 && day <= 9){ //
            day = "0" + day;
        };
        if(Hours >= 0 && Hours <= 9){ //
            Hours = "0" + Hours;
        };
        if(Minutes >= 0 && Minutes <= 9){ //
            Minutes = "0" + Minutes;
        };
        if(Seconds >= 0 && Seconds <= 9){ //
            Seconds = "0" + Seconds;
        };
        var currentdate = now.getFullYear() + "-" + month + "-" + day + " " + 
            Hours + ":" + Minutes + ":" + Seconds;
        return currentdate;
    },

 

js获取当前时间

原文:https://www.cnblogs.com/hjbky/p/9102363.html

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