首页 > 代码库 > 获取不同时间类型

获取不同时间类型

//获取本月份

 1 function getNewMonth(){
 2     var date=new Date;
 3     var year=date.getFullYear(); 
 4     var month=date.getMonth()+1;
 5     if(month<10){
 6         month="0"+month;
 7     }else{
 8         month=month;
 9     }
10     return year+"-"+month
11 }

//获取当前时间

 1 function getNewTime(){
 2     var date = new Date;
 3     var year = date.getFullYear();
 4     var month = date.getMonth()+1;
 5     var day = date.getDate();
 6     var hour = date.getHours();
 7     var minute = date.getMinutes();
 8     var second = date.getSeconds();
 9     if(month<10){
10         month="0"+month;
11     }else{
12         month=month;
13     }
14     if(day<10){
15         day="0"+day;
16     }else{
17         day=day;
18     }
19     if(hour<10){
20         hour="0"+day;
21     }else{
22         hour=hour;
23     }
24     if(minute<10){
25         minute="0"+minute;
26     }else{
27         minute=minute;
28     }
29     if(second<10){
30         second="0"+second;
31     }else{
32         second=second;
33     }
34     return year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
35 }

//获取当前日期

 1 function getNewDate(){
 2     var date = new Date;
 3     var year = date.getFullYear();
 4     var month = date.getMonth()+1;
 5     var day = date.getDate();
 6     if(month<10){
 7         month="0"+month;
 8     }else{
 9         month=month;
10     }
11     if(day<10){
12         day="0"+day;
13     }else{
14         day=day;
15     }
16     return year+"-"+month+"-"+day;
17 }

// 获取一周后日期

 1 function WeeklAgoDate(op){
 2     var now = new Date();
 3     var nowDayOfWeek = now.getDay();
 4     var date = new Date(now.getTime() + 7 * 24 * 3600 * 1000);
 5     var year = date.getFullYear();
 6     var month = date.getMonth() + 1;
 7     if(month<10){
 8         month="0"+month;
 9     }else{
10         month=month;
11     }
12     var day = date.getDate();
13     if(day<10){
14         day="0"+day;
15     }else{
16         day=day;
17     }
18     var op = year + ‘-‘ + month + ‘-‘ + day;
19     return op;
20 }

 

获取不同时间类型