码迷,腾讯三分彩 www.csbesbj.com
腾讯三分彩 > Web开发 > 详细

www.t87.com:js获取当前时间(包含am pm)

时间:2018-05-18 13:58:44      阅读:5886      评论:0      收藏:0      [点我收藏+]

腾讯三分彩 www.csbesbj.com 标签:seconds   span   minutes   mon   lse   cond   col   second   code   

var fn = function(){
    var now = new Date;
    var y = now.getFullYear();
    var m = now.getMonth();
    var d = now.getDate();
    var h = now.getHours();
    var mm = now.getMinutes();
    var s = now.getSeconds();
    var str;
    if(h>12) {
        h -= 12;
        str = " PM";
    }else{
        str = " AM";
    }
    h = h < 10 ? "0" + h : h;
    d = d < 10 ? "0" + d : d;
    m = m < 10 ? "0" + m : m;
    mm = mm < 10 ? "0" + mm : mm;
    s = s < 10 ? "0" + s : s;
    var xy = y + "/" + m + "/" + d + "," + h + ":" + mm + ":" + s;
    xy += str;
    return xy;
};
 
console.info(fn());

 

js获取当前时间(包含am pm)

标签:seconds   span   minutes   mon   lse   cond   col   second   code   

原文地址:https://www.cnblogs.com/congfeicong/p/9055173.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
? 2014 腾讯三分彩 www.csbesbj.com 版权所有 京ICP备13008772号-2
迷上了代码!