当前位置 : 主页 > 网页制作 > JQuery >

Jquery时间戳转换为字符串时间

来源:互联网 收集:自由互联 发布时间:2021-06-15
1 // 时间戳转换 2 function createTime(v){ 3 var date = new Date(v); 4 var y = date.getFullYear(); 5 var m = date.getMonth()+1 ; 6 m = m10?‘0‘+ m:m; 7 8 var d = date.getDate(); 9 d = d10?("0"+ d):d; 10 11 var h = date.getHours(); 12
 1 //时间戳转换
 2 function createTime(v){
 3     var date = new Date(v);
 4     var y = date.getFullYear();
 5     var m = date.getMonth()+1;
 6     m = m<10?‘0‘+m:m;
 7 
 8     var d = date.getDate();
 9     d = d<10?("0"+d):d;
10 
11     var h = date.getHours();
12     h = h<10?("0"+h):h;
13 
14     var M = date.getMinutes();
15     M = M<10?("0"+M):M;
16 
17     var oHour = date.getHours()
18     oHour = oHour<10?("0"+oHour):oHour;
19 
20     var oMin = date.getMinutes() 
21     oMin = oMin<10?("0"+oMin):oMin;
22 
23     var oSen = date.getSeconds()
24     oSen = oSen<10?("0"+oSen):oSen;
25 
26     var str = y+"-"+m+"-"+d+" "+oHour+":"+oMin+":"+oSen
27     return str;
28 }
网友评论