听说code能改变world,所以就学了

javascript Date函数

 1 <script type="text/javascript">
 2 
 3     function writeDate()Info() {
 4 
 5         var date;
 6 
 7         var year = "";
 8 
 9         var month = "";
10 
11         var day = "";        
12 
13         var ampm = "";
14 
15         var ampmhour = "";
16 
17         var minute = "";
18 
19         var weekday = "";
20 
21         
22 
23         date = new Date()();
24 
25         year = date.getFullYear();
26 
27         month = date.getMonth() < 9 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
28 
29         day = date.getDate()() < 10 ? "0" + date.getDate() : date.getDate();
30 
31         ampm = date.getHours() < 12 ? "上午" : "下午";
32 
33         ampmhour = date.getHours() < 12 ? date.getHours() : date.getHours() - 12;
34 
35         ampmhour = ("0" + ampmhour).substr(-2, 2);
36 
37         minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
38 
39         weekday = date.getDay();
40 
41         if (weekday == 0)
42 
43             weekday = " 星期日";
44 
45         else if (weekday == 1)
46 
47             weekday = " 星期一";
48 
49         else if (weekday == 2)
50 
51             weekday = " 星期二";
52 
53         else if (weekday == 3)
54 
55             weekday = " 星期三";
56 
57         else if (weekday == 4)
58 
59             weekday = " 星期四";
60 
61         else if (weekday == 5)
62 
63             weekday = " 星期五";
64 
65         else if (weekday == 6)
66 
67             weekday = " 星期六";
68 
69         document.write(year + "-" + month + "-" + day + " " + ampmhour + ":" + minute + " " + ampm + " " + weekday);
70 
71     }
72 
73 </script>

 


将需要的地方调用此函数即可(例如在哪个控件上增加事件:onclick="writeDateInfo();")

posted @ 2013-11-21 16:57  李腾  阅读(194)  评论(0编辑  收藏  举报

如果我加了黑链呢:http://liteng.org