推广网站的软件,包头移动的网站建设,wordpress修改ftp,优秀网页设计平台JS中获取时间很常见#xff0c;凑凑热闹#xff0c;也获取一个时间对象试试 首先#xff0c;先了解js的获取时间函数如下#xff1a; var myDate new Date(); //创建一个时间对象 myDate.getYear(); // 获取当前年份#xff08;2位#x… JS中获取时间很常见凑凑热闹也获取一个时间对象试试 首先先了解js的获取时间函数如下 var myDate new Date(); //创建一个时间对象 myDate.getYear(); // 获取当前年份2位 myDate.getFullYear(); // 获取当前完整的年份4位1970---- myDate.getMonth(); // 获取当前月份0--11, 0 代表1月 myDate.getDate(); // 获取当前是哪一日 1----31 myDate.getDay(); // 获取当前是哪一天即星期几0---6 0代表星期天 myDate.getTime(); // 获取当前时间的毫秒数从1970.1.1开始计算 myDate.getHours(); // 获取当前时间的小时数0---23 myDate.getMinutes(); //获取当前时间的分钟数 0---59 myDate.getSeconds(); // 获取当前时间的秒数 0---59 myDate.getMilliseconds(); // 获取当前时间的毫秒数 0---999 myDate.toLocaleDateString(); // 获取当前时间的日期 myDate.toLocaleTimeString(); // 获取当前时间 myDate.toLocaleString(); //获取当前日期与时间 创建一个时间如下 1 !DOCTYPE html2 html langen3 head4 meta charsetUTF-85 titleDocument/title6 style7 .box{8 margin:200px auto;9 width:400px;
10 }
11 span,code{
12 display: inline-block;
13 font-size: 75px;
14 }
15 /style
16 script
17 window.onload function(){
18
19 function OTime(){
20 this.aspan document.querySelectorAll(.box span);
21 };
22 OTime.prototype.todouble function( n ){
23 return n10 ? n : 0 n ;
24 };
25 OTime.prototype.getcurtime function(){
26 var odate new Date();
27 var OHour odate.getHours();
28 var OMin odate.getMinutes();
29 var OSec odate.getSeconds();
30 return this.todouble( OHour ) this.todouble( OMin ) this.todouble( OSec ) ;
31 };
32 OTime.prototype.setcurTime function(){
33 var str this.getcurtime();
34 for(var i0;ithis.aspan.length;i){
35 this.aspan[i].innerHTML str.charAt( i );
36 };
37 };
38 OTime.prototype.showtime function(){
39 this.setcurTime();
40 var that this ;
41 setInterval(function(){
42 that.setcurTime();
43 },1000);
44 };
45 var curtime new OTime();
46 curtime.showtime();
47
48 };
49 /script
50 /head
51 body
52 div classbox
53 span2/span
54 span2/span
55 code:/code
56 span1/span
57 span1/span
58 code:/code
59 span3/span
60 span3/span
61 /div
62 /body
63 /html 运行结果 转载于:https://www.cnblogs.com/huanying2015/p/8018407.html