码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript 格式化时间

时间:2016-01-08 13:04:04      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

 

 1 //格式化 yyyy-MM-dd hh:mm:ss
 2 function renderTime(date) {
 3     if (date == ‘‘ || date == null) {
 4         return ‘‘;
 5     }
 6     var da = new Date(parseInt(date.replace("/Date(", "").replace(")/", "").split("+")[0]));
 7     return da.getFullYear() + "-" + (da.getMonth() + 1) + "-" + da.getDate() + " " + da.getHours() + ":" + da.getMinutes() + ":" + da.getSeconds();
 8 }
 9 
10 //格式化 yyyy-0M-0d
11 function renderDate(date) {
12     if (date == ‘‘ || date == null) {
13         return ‘‘;
14     }
15     var da = new Date(parseInt(date.replace("/Date(", "").replace(")/", "").split("+")[0]));
16     return da.getFullYear() + "-" + (da.getMonth() + 1) + "-" + da.getDate();
17 }
18 
19 //格式化时间  yyyy-mm-dd
20 function getFormatDate(date) {
21 
22     if (date == ‘‘ || date == null) {
23         return ‘‘;
24     }
25     var day = new Date(parseInt(date.replace("/Date(", "").replace(")/", "").split("+")[0]));
26     var Year = 0;
27     var Month = 0;
28     var Day = 0;
29     var CurrentDate = "";
30     //初始化时间 
31     //Year= day.getYear();//有火狐下2008年显示108的bug 
32     Year = day.getFullYear();//ie火狐下都可以 
33     Month = day.getMonth() + 1;
34     Day = day.getDate();
35     //Hour = day.getHours(); 
36     // Minute = day.getMinutes(); 
37     // Second = day.getSeconds(); 
38     CurrentDate += Year + "-";
39     if (Month >= 10) {
40         CurrentDate += Month + "-";
41     }
42     else {
43         CurrentDate += "0" + Month + "-";
44     }
45     if (Day >= 10) {
46         CurrentDate += Day;
47     }
48     else {
49         CurrentDate += "0" + Day;
50     }
51     return CurrentDate;
52 }

 

JavaScript 格式化时间

标签:

原文地址:http://www.cnblogs.com/gaozejie/p/5112720.html

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