读取系统时间

getLocalTime() {
    //  如果时分秒为小于10 的数字在其前面添加“0”
            function formatTime(f) {

    // 判断时、分、秒是否小于10,小于10的话前面加“0”
                return f < 10 ?"0" +  f : f
            }
            var myDate = new Date(); // 读取日期
               h = myDate.getHours(); // 读取时
                 m = myDate.getMinutes(); // 读取分
                 s = myDate.getSeconds(); // 读取秒
            return formatTime(h) + ":" + formatTime(m) + ":" + formatTime(s);  // 拼接时间
        }

posted @ 2019-04-08 10:39  Cy_0710  阅读(344)  评论(0)    收藏  举报