JS Date
<script language=javascript> //一天含 86,400,000 毫秒(24* 60 * 60*1000) //今天 function showToDay() { var Nowdate=new Date(); M=Number(Nowdate.getMonth())+1 return Nowdate.getYear()+"-"+M+"-"+Nowdate.getDate(); } //本週第一天 function showWeekFirstDay() { var Nowdate=new Date(); var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000); return WeekFirstDay; } //本週最後一天 function showWeekLastDay() { var Nowdate=new Date(); var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000); var WeekLastDay=new Date((WeekFirstDay/1000+6*86400)*1000); return WeekLastDay; } //本月第一天 function showMonthFirstDay() { var Nowdate=new Date(); var MonthFirstDay=new Date(Nowdate.getYear(),Nowdate.getMonth(),1); return MonthFirstDay; } //本月最後一天 function showMonthLastDay() { var Nowdate=new Date(); var MonthNextFirstDay=new Date(Nowdate.getYear(),Nowdate.getMonth ()+1,1); var MonthLastDay=new Date(MonthNextFirstDay-86400000); return MonthLastDay; } //上月第一天 function showPreviousFirstDay() { var MonthFirstDay=showMonthFirstDay() return new Date(MonthFirstDay.getYear(),MonthFirstDay.getMonth()- 1,1) } //上月最後一天 function showPreviousLastDay() { var MonthFirstDay=showMonthFirstDay(); return new Date(MonthFirstDay-86400000); } //上週第一天 function showPreviousFirstWeekDay() { var WeekFirstDay=showWeekFirstDay() return new Date(WeekFirstDay-86400000*7) } //上週最後一天 function showPreviousLastWeekDay() { var WeekFirstDay=showWeekFirstDay() return new Date(WeekFirstDay-86400000) } //上一天 function showPreviousDay() { var MonthFirstDay=new Date(); return new Date(MonthFirstDay-86400000); } //下一天 function showNextDay() { var MonthFirstDay=new Date(); return new Date((MonthFirstDay/1000+86400)*1000); } //下週第一天 function showNextFirstWeekDay() { var MonthFirstDay=showWeekLastDay() return new Date((MonthFirstDay/1000+86400)*1000) } //下週最後一天 function showNextLastWeekDay() { var MonthFirstDay=showWeekLastDay() return new Date((MonthFirstDay/1000+7*86400)*1000) } //下月第一天 function showNextFirstDay() { var MonthFirstDay=showMonthFirstDay() return new Date(MonthFirstDay.getYear(),MonthFirstDay.getMonth() +1,1) } //下月最後一天 function showNextLastDay() { var MonthFirstDay=showMonthFirstDay() return new Date(new Date(MonthFirstDay.getYear (),MonthFirstDay.getMonth()+2,1)-86400000) } function Date.prototype.toString(){ return this.getFullYear()+"-"+(this.getMonth()+1)+"-"+this.getDate (); } function setDate(num){ if(num==1){ document.all.dateDate.value=showMonthFirstDay(); document.all.dateDate2.value=showMonthLastDay(); } if(num==2){ document.all.dateDate.value=showWeekFirstDay(); document.all.dateDate2.value=showWeekLastDay(); } if(num==3){ document.all.dateDate.value=showToDay(); document.all.dateDate2.value=showToDay(); } if(num==4){ document.all.dateDate.value=showPreviousFirstDay(); document.all.dateDate2.value=showPreviousLastDay(); } if(num==5){ document.all.dateDate.value=showNextFirstDay(); document.all.dateDate2.value=showNextLastDay(); } if(num==6){ document.all.dateDate.value=showPreviousFirstWeekDay(); document.all.dateDate2.value=showPreviousLastWeekDay(); } if(num==7){ document.all.dateDate.value=showNextFirstWeekDay(); document.all.dateDate2.value=showNextLastWeekDay(); } if(num==8){ document.all.dateDate.value=showPreviousDay(); document.all.dateDate2.value=showPreviousDay(); } if(num==9){ document.all.dateDate.value=showNextDay(); document.all.dateDate2.value=showNextDay(); } } </script> <input name=dateDate type=text>-><input name=dateDate2 type=text> <input name=haha type=button value="上一月" onclick=setDate (4)> <input name=haha type=button value="本月" onclick=setDate(1) > <input name=haha type=button value="下一月" onclick=setDate(5) > <input name=haha type=button value="上一週" onclick=setDate(6) > <input name=haha type=button value="本週" onclick=setDate(2)> <input name=haha type=button value="下一週" onclick=setDate(7) > <input name=haha type=button value="上一天" onclick=setDate(8) > <input name=haha type=button value="今天" onclick=setDate(3)> <input name=haha type=button value="下一天" onclick=setDate(9)>
相關文章
- js轉換/Date(........)/JS
- js本地物件——Date()JS物件
- 特殊字元、Date、JS應用字元JS
- js學習三-日期DateJS
- js new Date怪異行為JS
- js報錯:TypeError: Date is not a constructorJSErrorStruct
- js Date.now()函式用法JS函式
- 小陳學JS js內建物件 Date物件JS物件
- js基礎–Date.parse()與Date.getTime()方法詳解JS
- js物件陣列Date的比較JS物件陣列
- BUG: JS 修改Date的TimezoneJS
- javascript得知 - js的Date物件函式JavaScriptJS物件函式
- js Date()建構函式簡單介紹JS函式
- JS中的Math物件,陣列,和Date物件JS物件陣列
- JS對日期、時間校驗;相容IE new Date()JS
- js date物件的獲取時間日期常用方法JS物件
- js Date()建構函式建立時間日期物件JS函式物件
- date_format(date,frm) 詳解ORM
- shell date 詳細用法 如date --date='1 month ago' '+%Y%m'Go
- js實現重寫new Date()相容IE6以上JS
- mysql DATE_ADD DATE_SUBMySql
- date 物件物件
- JavaScript Date()JavaScript
- Java DateJava
- date命令
- javascript dateJavaScript
- jackson 中JsonFormat date型別欄位的使用JSONORM型別
- JS原生Date型別方法的一些冷知識JS型別
- java util date轉換成java sql dateJavaSQL
- js將時間日期字串轉換為時間日期Date物件JS字串物件
- javaScript系列:js中獲取時間new Date()詳細介紹JavaScriptJS
- JSON.stringify轉換Date不正確的解決方法JSON
- Mysql date_format 與 Oracle to_char(date,’format’)MySqlORMOracle
- 解決IE、firefox瀏覽器下JS的new Date()的值為Invalid Date、NaN-NaN的問題Firefox瀏覽器JSNaN
- Moment.js遇到Deprecation warning: moment construction falls back to js Date 解決方法JSStruct
- JavaScript Date valueOf()JavaScript
- JavaScript Date 物件JavaScript物件
- JavaScript Date() 方法JavaScript