html5+css+jquery完成時間顯示

來源:互聯網
上載者:User

HTML5代碼

<div  id="time">            <span id="hour"></span>            <span id="data"></span></div>

CSS代碼

#time{    float: right;    width: auto;    padding:0 50px;    border-left: 2px solid  rgba(255,255,255,.3);    height: 54px;    margin-top: 13px;    margin-left: 40px;    color:#fff;    cursor: default;    text-align: center;}#hour{    display: block;    width: auto;    font-size: 22px;    height: 34px;    line-height: 34px;    color:#fff;    cursor: default;}#data{    display: block;    width: auto;    font-size: 10px;    height:20px;    line-height: 20px;    color:#fff;    cursor: default;}

jquery代碼

/*時間計數器*/function p(s) {    return s < 10 ? '0' + s: s;}function nowtime() {    var myDate = new Date();    var year = myDate.getFullYear(); //擷取當前年    var month = myDate.getMonth()+1; //擷取當前月    var date = myDate.getDate();     //擷取當前日    var h = myDate.getHours();       //擷取當前小時數(0-23)    var m = myDate.getMinutes();     //擷取當前分鐘數(0-59)    var s = myDate.getSeconds();    var data = year+ '-' + p(month)+ "-"+ p(date);    var hour = p(h)+ ':'+ p(m);    $("#data").html(data);    $("#hour").html(hour);}nowtime();setInterval(nowtime,1000);
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.