日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

获取今天,昨天,本周,上周,本月,上月时间

發(fā)布時間:2024/4/17 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 获取今天,昨天,本周,上周,本月,上月时间 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1 //獲取今天 2 var nowDate= new Date(); //當天日期 3 console.log(nowDate); 4 //今天是本周的第幾天 5 var nowDayOfWeek= nowDate.getDay(); 6 console.log(nowDayOfWeek); 7 //當前日 8 var nowDay = nowDate.getDate(); 9 console.log(nowDay); 10 //當前月 11 var nowMonth = nowDate.getMonth(); 12 console.log(nowMonth); 13 //當前年 14 var nowYear = nowDate.getFullYear(); 15 console.log(nowYear); 16 //var nowHours = nowDate.getHours(); 17 //var nowMinutes = nowDate.getMinutes(); 18 //var nowSeconds = nowDate.getSeconds(); 19 20 nowYear += (nowYear < 2000) ? 1900 : 0; // 21 console.log(nowYear); 22 23 24 var lastMonthDate = new Date(); //上月日期 25 console.log(lastMonthDate); 26 27 lastMonthDate.setDate(1); 28 console.log(lastMonthDate.setDate(1)); 29 30 lastMonthDate.setMonth(lastMonthDate.getMonth()-1); 31 console.log(lastMonthDate.setMonth(lastMonthDate.getMonth()-1)); 32 33 var lastYear = lastMonthDate.getYear(); 34 console.log(lastYear); 35 36 var lastMonth = lastMonthDate.getMonth(); 37 console.log(lastMonth); 38 39 40 //格式化日期:yyyy-MM-dd 41 function formatDate(date) { 42 var myyear = date.getFullYear(); 43 var mymonth = date.getMonth()+1; 44 var myweekday = date.getDate(); 45 //var myHours = date.getHours(); 46 //var myMinutes = date.getMinutes(); 47 //var mySeconds = date.getSeconds(); 48 49 if(mymonth < 10){ 50 mymonth = "0" + mymonth; 51 } 52 if(myweekday < 10){ 53 myweekday = "0" + myweekday; 54 } 55 //if(myHours < 10){ 56 // myHours = "0" + myHours; 57 //} 58 //if(myMinutes < 10){ 59 // myMinutes = "0" + myMinutes; 60 //} 61 return (myyear+"/"+mymonth + "/" + myweekday); 62 //return (myyear+"/"+mymonth + "/" + myweekday + " " + myHours+ ":" + myMinutes); 63 } 64 65 //獲得某月的天數(shù) 66 function getMonthDays(myMonth){ 67 var monthStartDate = new Date(nowYear, myMonth, 1); 68 var monthEndDate = new Date(nowYear, myMonth + 1, 1); 69 var days = (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24); 70 return days; 71 } 72 73 ////獲得本季度的開始月份 74 //function getQuarterStartMonth(){ 75 // var quarterStartMonth = 0; 76 // if(nowMonth<3){ 77 // quarterStartMonth = 0; 78 // } 79 // if(2<6){ 80 // quarterStartMonth = 3; 81 // } 82 // if(5<9){ 83 // quarterStartMonth = 6; 84 // } 85 // if(nowMonth>8){ 86 // quarterStartMonth = 9; 87 // } 88 // return quarterStartMonth; 89 //} 90 91 92 //今天 93 $scope.toDay = function(){ 94 var getCurrentDate = new Date(); 95 var getCurrentDate = formatDate(getCurrentDate); 96 $scope.today = getCurrentDate; 97 console.log($scope.today); 98 $("#jqueryPickerTime3").val($scope.today); 99 $("#jqueryPickerTime4").val($scope.today); 100 }; 101 102 //昨天 103 $scope.yesTerDay = function(){ 104 var getYesterdayDate = new Date(nowYear, nowMonth, nowDay - 1); 105 var getYesterdayDate = formatDate(getYesterdayDate); 106 107 $scope.yesTday = getYesterdayDate; 108 console.log(getYesterdayDate); 109 $("#jqueryPickerTime3").val($scope.yesTday); 110 $("#jqueryPickerTime4").val($scope.yesTday); 111 }; 112 113 114 //獲得本周的開始日期 115 $scope.thisWeek = function(){ 116 var getWeekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek); 117 var getWeekStartDate = formatDate(getWeekStartDate); 118 $scope.tswkStart = getWeekStartDate; 119 console.log($scope.tswkStart); 120 $("#jqueryPickerTime3").val($scope.tswkStart); 121 //獲得本周的結(jié)束日期 122 var getWeekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek)); 123 var getWeekEndDate = formatDate(getWeekEndDate); 124 $scope.tswkEnd = getWeekEndDate; 125 console.log($scope.tswkEnd); 126 $("#jqueryPickerTime4").val($scope.tswkEnd); 127 }; 128 129 $scope.lastWeek = function(){ 130 //獲得上周的開始日期 131 var getUpWeekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek -7); 132 var getUpWeekStartDate = formatDate(getUpWeekStartDate); 133 $scope.startLastWeek = getUpWeekStartDate; 134 console.log($scope.startLastWeek); 135 $("#jqueryPickerTime3").val($scope.startLastWeek); 136 //獲得上周的結(jié)束日期 137 var getUpWeekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek - 7)); 138 var getUpWeekEndDate = formatDate(getUpWeekEndDate); 139 $scope.endLastWeek = getUpWeekEndDate; 140 console.log($scope.endLastWeek); 141 $("#jqueryPickerTime4").val($scope.endLastWeek); 142 143 144 }; 145 //本月 146 $scope.thisMonth = function(){ 147 //獲得本月的開始日期 148 var getMonthStartDate = new Date(nowYear, nowMonth, 1); 149 var getMonthStartDate = formatDate(getMonthStartDate); 150 $scope.startThisMonth = getMonthStartDate; 151 console.log($scope.startThisMonth); 152 $("#jqueryPickerTime3").val($scope.startThisMonth); 153 154 //獲得本月的結(jié)束日期 155 var getMonthEndDate = new Date(nowYear, nowMonth, getMonthDays(nowMonth)); 156 var getMonthEndDate = formatDate(getMonthEndDate); 157 $scope.endThisMonth = getMonthEndDate; 158 console.log($scope.endThisMonth); 159 $("#jqueryPickerTime4").val($scope.endThisMonth); 160 }; 161 //上月 162 $scope.lastMonth = function(){ 163 //獲得上月開始時間 164 var getLastMonthStartDate = new Date(nowYear, lastMonth+1, 1); 165 var getLastMonthStartDate = formatDate(getLastMonthStartDate); 166 167 $scope.startLastMonth = getLastMonthStartDate; 168 console.log($scope.startLastMonth); 169 170 $("#jqueryPickerTime3").val($scope.startLastMonth); 171 //獲得上月結(jié)束時間 172 var getLastMonthEndDate = new Date(nowYear, lastMonth+1, getMonthDays(lastMonth+1)); 173 var getLastMonthEndDate = formatDate(getLastMonthEndDate); 174 175 $scope.endLastMonth = getLastMonthEndDate; 176 console.log($scope.endLastMonth); 177 $("#jqueryPickerTime4").val($scope.endThisMonth); 178 };

?

轉(zhuǎn)載于:https://www.cnblogs.com/yaomin/p/6253146.html

總結(jié)

以上是生活随笔為你收集整理的获取今天,昨天,本周,上周,本月,上月时间的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。