1 <script> 2 function secToDate(sec){ 3 var now=new Date(sec); 4 var y=now.getFullYear(); 5 var m=now.getMonth()+1; 6 var d=now.getDate(); 7 var day=now.getDay(); 8 var hh=now.getHours(); 9 var mm=now.getMinutes(); 10 var ss=now.getSeconds(); 11 var days=["日","一","二","三","四","五","六"]; 12 hh=(hh<9)?"0"+hh:hh; 13 mm=(mm<9)?"0"+mm:mm; 14 return { 15 bookTime:y+"-"+m+"-"+d+" 周"+days[day]+" "+hh+":"+mm, 16 serviceTime:y+"-"+m+"-"+d+" "+hh+":"+mm 17 } 18 } 19 var date=secToDate(1476762967406); 20 var date2=secToDate(1476768453057); 21 console.log('预约时间:'+date.bookTime); 22 console.log('服务时间:'+date2.serviceTime); 23 </script>
获取天数
//得到某天的日期 function GetDateStr(AddDayCount) { //获取AddDayCount天后的日期 var dd = new Date(new Date().getTime() + AddDayCount*24*60*60*1000); var y = dd.getFullYear(); var m = dd.getMonth()+1;//获取当前月份(0-11,0代表1月) m = m<10?"0"+m:m; var d = dd.getDate(); d = d<10? "0"+d : d; return y+"-"+m+"-"+d; } //得到某天日期的“年”(2位) function GetYearStr(AddDayCount) { //获取AddDayCount天后的日期 var dd = new Date(new Date().getTime() + AddDayCount*24*60*60*1000); return dd.getYear(); } //得到某天日期的“年”(4位) function GetFullYearStr(AddDayCount) { //获取AddDayCount天后的日期 var dd = new Date(new Date().getTime() + AddDayCount*24*60*60*1000); return dd.getFullYear(); } //得到某天日期的“月” function GetMonthStr(AddDayCount) { //获取AddDayCount天后的日期 var dd = new Date(new Date().getTime() + AddDayCount*24*60*60*1000); var m = dd.getMonth()+1;//获取当前月份(0-11,0代表1月) m = m<10?"0"+m:m; return m; } //得到某天日期的“日” function GetDStr(AddDayCount) { //获取AddDayCount天后的日期 var dd = new Date(new Date().getTime() + AddDayCount*24*60*60*1000); var d = dd.getDate(); d = d<10? "0"+d : d; return d; } //得到某天日期的“周几” function GetDayStr(AddDayCount) { //获取AddDayCount天后的日期 var days=["日","一","二","三","四","五","六"]; var dd = new Date(new Date().getTime() + AddDayCount*24*60*60*1000); return days[dd.getDay()]; //获取当前星期X(0-6,0代表星期天) } //得到某天日期的“毫秒数” function GetTimeStr(AddDayCount) { //获取AddDayCount天后的日期 var dd = new Date(new Date().getTime() + AddDayCount*24*60*60*1000); return dd.getTime();//获取当前时间(从1970.1.1开始的毫秒数) } //得到某天日期的“小时” function GetHoursStr(AddDayCount) { //获取AddDayCount天后的日期 var dd = new Date(new Date().getTime() + AddDayCount*24*60*60*1000); var h = dd.getHours();//获取当前小时数(0-23) h = h<10? "0"+h : h; return h; } //得到某天日期的“分钟” function GetMinutesStr(AddDayCount) { //获取AddDayCount天后的日期 var dd = new Date(new Date().getTime() + AddDayCount*24*60*60*1000); var m =dd.getMinutes();//获取当前分钟数(0-59) m = m<10?"0"+m:m; return m; } //得到某天日期的“秒数” function GetSecondsStr(AddDayCount) { //获取AddDayCount天后的日期 var dd = new Date(new Date().getTime() + AddDayCount*24*60*60*1000); var s =dd.getSeconds();////获取当前秒数(0-59) s = s<10?"0"+s:s; return s; } //得到某天日期的“毫秒数” function GetMillisecondsStr(AddDayCount) { //获取AddDayCount天后的日期 var dd = new Date(new Date().getTime() + AddDayCount*24*60*60*1000); var ms =dd.getMilliseconds();//获取当前毫秒数(0-999) ms = ms<10?"0"+ms:ms; return ms; } //得到某天的日期 function GetLocaleDateStr(AddDayCount) { //获取AddDayCount天后的日期 var dd = new Date(new Date().getTime() + AddDayCount*24*60*60*1000); return dd.toLocaleDateString();//获取当前日期 } //得到某天的时间 function GetLocaleTimeStr(AddDayCount) { //获取AddDayCount天后的日期 var dd = new Date(new Date().getTime() + AddDayCount*24*60*60*1000); return dd.toLocaleTimeString();//获取当前时间 } //得到某天的日期与时间 function GetLocaleStr(AddDayCount) { //获取AddDayCount天后的日期 var dd = new Date(new Date().getTime() + AddDayCount*24*60*60*1000); return dd.toLocaleString();//获取日期与时间 }