码迷,mamicode.com
首页 > Web开发 > 详细

HTML 中获取现在时间,实时时间获取

时间:2017-08-11 13:34:51      阅读:338      评论:0      收藏:0      [点我收藏+]

标签:one   display   and   gif   class   www   href   .com   bsp   

 

JavaScript   Date 对象

                           Date 对象用于处理日期与实际。

创建 Date 对象:

                 var now  =  new Date().

 

方法描述
getDate() 从 Date 对象返回一个月中的某一天 (1 ~ 31)。
getDay() 从 Date 对象返回一周中的某一天 (0 ~ 6)。
getFullYear() 从 Date 对象以四位数字返回年份
getHours() 返回 Date 对象的小时 (0 ~ 23)。
getMilliseconds() 返回 Date 对象的毫秒(0 ~ 999)。
getMinutes() 返回 Date 对象的分钟 (0 ~ 59)。
getMonth() 从 Date 对象返回月份 (0 ~ 11)。
getSeconds() 返回 Date 对象的秒数 (0 ~ 59)。
   
setDate() 设置 Date 对象中月的某一天 (1 ~ 31)。
setFullYear() 设置 Date 对象中的年份(四位数字)。
setHours() 设置 Date 对象中的小时 (0 ~ 23)。
setMilliseconds() 设置 Date 对象中的毫秒 (0 ~ 999)。
setMinutes() 设置 Date 对象中的分钟 (0 ~ 59)。
setMonth() 设置 Date 对象中月份 (0 ~ 11)。
setSeconds() 设置 Date 对象中的秒钟 (0 ~ 59)。
setTime() setTime() 方法以毫秒设置 Date 对象。
   

 

 

技术分享
<script type="text/javascript">

    var span = document.getElementById("spandate");

    var now = new Date();

    var year = now.getFullYear();//
    var month = now.getMonth() + 1;//月  (注意:月份+1)
    var date = now.getDate();//
   
    if (month < 10) {
        month = "0" + month;
    }
    if (date < 10) {
        date = "0" + date;
    }
   
    span.innerText = year + "-" + month + "-" + date;
   


</script>
js 中获取现在时间 年-月-日

 

HTML 中获取现在时间,实时时间获取

标签:one   display   and   gif   class   www   href   .com   bsp   

原文地址:http://www.cnblogs.com/Tanghongchang/p/7345327.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!