午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

JavaScript實現時間范圍效果

瀏覽:13日期:2023-06-05 08:38:29

本文實例為大家分享了JavaScript實現時間范圍效果的具體代碼,供大家參考,具體內容如下

當前時間往前的時間范圍(六個月之前)

效果圖

JavaScript實現時間范圍效果

js文件代碼片

/*查詢日期區間(當前時間往前) Add By Vivian 2020/12/04 *///rangeVal:兩個日期的間隔符 num:隔多少 timeType:相隔時間類型function funGetRangeDateByLess(rangeVal,num,timeType){ var returnVal=''; var otherVal=''; var otherTime=''; var curTime = new Date(); var curTimeVal= curTime.getFullYear() + ’-’ + PrefixZero((curTime.getMonth() + 1), 2) + ’-’ + PrefixZero(curTime.getDate(), 2); switch (timeType) {case 1://分 var addMinutes = curTime.setMinutes(curTime.getMinutes() - num); otherTime=new Date(addMinutes); break;case 2://時 var addMinutes = curTime.setHours(curTime.getHours() - num); otherTime=new Date(addMinutes); break;case 3://天 var addDate = curTime.setDate(curTime.getDate() - num); otherTime=new Date(addDate); break;case 4://月 var addMonth = curTime.setMonth(curTime.getMonth() - num); otherTime=new Date(addMonth); break;case 5://年 var addYear = curTime.setFullYear(curTime.getFullYear() - num); otherTime=new Date(addYear); break;default: break; } otherVal= otherTime.getFullYear() + ’-’ + PrefixZero((otherTime.getMonth() + 1), 2) + ’-’ + PrefixZero(otherTime.getDate(), 2); return returnVal=otherVal+rangeVal+curTimeVal;}/*自動補零 Add By Vivian 2020/12/04 */function PrefixZero(num, n) { return (Array(n).join(0) + num).slice(-n);}

使用代碼片

var fillhelptime=funGetRangeDateByLess(' , ',6,4);laydate.render({elem: '#fillhelptime',range: ',',type: ’date’,value:fillhelptime,//默認值});某個日期的時間范圍(前后多少天)

效果圖

JavaScript實現時間范圍效果

js文件代碼片

/*查詢日期區間(某個日期前后多少天) Add By Vivian 2021/04/06 *///rangeVal:兩個日期的間隔符 date:某個日期 beforeDays:前N天 afterDays:后N天function funGetRangeDateByBeforeAndAfter(rangeVal,date,beforeDays,afterDays){ var dateVaule1 = new Date(date);//轉換成時間格式 var dateVaule2 = new Date(date);//轉換成時間格式 var startDate = new Date(dateVaule1.setDate(dateVaule1.getDate() - beforeDays));//前N天 var endDate = new Date(dateVaule2.setDate(dateVaule2.getDate() + afterDays));//后N天 var date1= startDate.getFullYear() + ’-’ + PrefixZero((startDate.getMonth() + 1), 2) + ’-’ + PrefixZero(startDate.getDate(), 2); var date2= endDate.getFullYear() + ’-’ + PrefixZero((endDate.getMonth() + 1), 2) + ’-’ + PrefixZero(endDate.getDate(), 2); var returnVal=date1+rangeVal+date2; return returnVal;}/*自動補零 Add By Vivian 2020/12/04 */function PrefixZero(num, n) { return (Array(n).join(0) + num).slice(-n);}某個時間點的時間范圍(前后多少天)

效果圖

JavaScript實現時間范圍效果

js文件代碼片

/*查詢日期區間(某個時間點前后多少時間) Add By Vivian 2021/04/06 *///rangeVal:兩個日期的間隔符 timeType:相隔時間類型 date:某個日期 beforeDays:前N天 afterDays:后N天function funGetRangeDateByBeforeAndAfter(rangeVal,timeType,date,beforeNum,afterNum){ var dateVaule1 = new Date(date);//轉換成時間格式 var dateVaule2 = new Date(date);//轉換成時間格式 var startDate = ''; var endDate = ''; switch (timeType) {case 1://分 startDate = new Date(dateVaule1.setMinutes(dateVaule1.getMinutes() - beforeNum));//前N分鐘 endDate = new Date(dateVaule2.setMinutes(dateVaule2.getMinutes() + afterNum));//后N分鐘 break;case 2://時 startDate = new Date(dateVaule1.setHours(dateVaule1.getHours() - beforeNum));//前N小時 endDate = new Date(dateVaule2.setHours(dateVaule2.getHours() + afterNum));//后N小時 break;case 3://天 startDate = new Date(dateVaule1.setDate(dateVaule1.getDate() - beforeNum));//前N天 endDate = new Date(dateVaule2.setDate(dateVaule2.getDate() + afterNum));//后N天 break;case 4://月 startDate = new Date(dateVaule1.setMonth(dateVaule1.getMonth() - beforeNum));//前N月 endDate = new Date(dateVaule2.setMonth(dateVaule2.getMonth() + afterNum));//后N月 break;case 5://年 startDate = new Date(dateVaule1.setFullYear(dateVaule1.getFullYear() - beforeNum));//前N年 endDate = new Date(dateVaule2.setFullYear(dateVaule2.getFullYear() + afterNum));//后N年 var addYear = curTime.setFullYear(curTime.getFullYear() - num); break;default: break; } var returnVal1= startDate.getFullYear() + ’-’ + PrefixZero((startDate.getMonth() + 1), 2) + ’-’ + PrefixZero(startDate.getDate(), 2); var returnVal2= endDate.getFullYear() + ’-’ + PrefixZero((endDate.getMonth() + 1), 2) + ’-’ + PrefixZero(endDate.getDate(), 2); var returnVal=returnVal1+rangeVal+returnVal2; return returnVal;}/*自動補零 Add By Vivian 2020/12/04 */function PrefixZero(num, n) { return (Array(n).join(0) + num).slice(-n);}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 超碰在线人 | 可以免费看的av | 亚洲字幕av | 黄视频在线播放 | 国产精品a久久久久 | 日韩一区二区三区不卡 | 久久免费资源 | 久久av色| 欧美日韩国产黄色 | av免费国产| 麻豆小视频 | 亚洲精品在线免费播放 | 91成人精品一区在线播放 | 国产区在线 | 草民午夜理伦三级 | 黄色一级免费网站 | 日本精品视频一区二区三区 | 在线看黄网 | 免费黄网站在线观看 | 麻豆md0077饥渴少妇 | 青青操国产 | 成人免费大片黄在线播放 | 亚洲午夜在线播放 | 成人aⅴ视频 | 麻豆理论片 | 久久伊人影视 | 亚洲a网 | 99色在线| 欧美成年人| 五月激情婷婷丁香 | 成人一区二区三区视频 | 北京富婆泄欲对白 | 国产精品久久久久久久精 | av在线你懂的 | 国产综合精品久久久久成人av | 国产日产精品一区二区三区 | 中文字幕中出 | 欧美一级在线免费观看 | 久久久久久国产 | 国产成人精品一区二区三区网站观看 | 黄色大片免费看 |