时间戳的相互转化

 1 //hope_time的格式是09:34分
 2 var hope_time = $('#time-options').val();
 3 var myDate = new Date();
 4 var year = myDate.getFullYear();
 5 var month = myDate.getMonth() + 1;
 6 var day = myDate.getDate();
 7 if (month < 10) month = "0" + month;
 8 if (date < 10) date = "0" + date;
 9 //转化为年月日时分秒,秒数填0
10 var date = ""+year+"-"+month+"-"+day+" "+hope_time+":00";  
11 //将该时间段时间转化为时间戳
12 var timestamp2 = Date.parse(new Date(date));
13 //转化为毫秒
14 timestamp2 = timestamp2 / 1000;
15 
16 //时间戳转化为年月日时分秒格式
17 function getDate(uData){ 
18     var myDate = new Date(uData*1000);
19     var year = myDate.getFullYear();
20     var month = myDate.getMonth() + 1;
21     var day = myDate.getDate();
22     var hours = myDate.getHours();
23     var minutes = myDate.getMinutes();
24     var second = myDate.getSeconds();
25     return year + '-' + month + '-' + day +'   '+ hours + ':' + minutes + ':' + second; 
26 }

 

posted @ 2016-09-06 09:28  ^^-^^-  阅读(186)  评论(0编辑  收藏  举报