js获取当前时间

Posted 安静的女汉纸

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js获取当前时间相关的知识,希望对你有一定的参考价值。

/**
     * 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获取当前时间的主要内容,如果未能解决你的问题,请参考以下文章

js常用代码片段(更新中)

没有使用 navController.currentDestination?.id 获取当前片段 ID

web代码片段

HLS.js 获取视频片段信息

JS获取URL的参数

Android - 获取当前片段