Calculate the range of last month, next month, last week, and next week.

Source: Internet
Author: User
<Script language = JavaScript>
// Today
Function showtoday ()
{
VaR nowdate = new date ();
M = Number (nowdate. getmonth () + 1
Return nowdate. getyear () + "-" + M + "-" + nowdate. getdate ();
}

// The first day of the week
Function showweekfirstday ()
{
VaR nowdate = new date ();
VaR weekfirstday = new date (nowdate-(nowdate. getday ()-1) * 86400000 );
Return weekfirstday;
}
// Last day of the week
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;
}

// The first day of the month
Function showmonthfirstday ()
{
VaR nowdate = new date ();
VaR monthfirstday = new date (nowdate. getyear (), nowdate. getmonth (), 1 );
Return monthfirstday;
}
// Last day of the month
Function showmonthlastday ()
{
VaR nowdate = new date ();
VaR monthnextfirstday = new date (nowdate. getyear (), nowdate. getmonth () + 1, 1 );
VaR monthlastday = new date (MonthNextFirstDay-86400000 );
Return monthlastday;
}
// The first day of last month
Function showpreviusfirstday ()
{
VaR monthfirstday = showmonthfirstday ()
Return new date (monthfirstday. getyear (), monthfirstday. getmonth ()-1, 1)
}
// Last day of last month
Function showpreviuslastday ()
{
VaR monthfirstday = showmonthfirstday ();
Return new date (MonthFirstDay-86400000 );
}
// The first day of last week
Function showpreviusfirstweekday ()
{
VaR weekfirstday = showweekfirstday ()
Return new date (WeekFirstDay-86400000 * 7)
}
// Last day of last week
Function showpreviuslastweekday ()
{
VaR weekfirstday = showweekfirstday ()
Return new date (WeekFirstDay-86400000)
}
// Last day
Function showpreviusday ()
{
VaR monthfirstday = new date ();
Return new date (MonthFirstDay-86400000 );
}
// Next day
Function shownextday ()
{
VaR monthfirstday = new date ();
Return new date (monthfirstday/1000 + 86400) * 1000 );
}
// The first day of next week
Function shownextfirstweekday ()
{
VaR monthfirstday = showweeklastday ()
Return new date (monthfirstday/1000 + 86400) * 1000)
}
// Last day of next week
Function shownextlastweekday ()
{
VaR monthfirstday = showweeklastday ()
Return new date (monthfirstday/1000 + 7*86400) * 1000)
}
// The first day of next month
Function shownextfirstday ()
{
VaR monthfirstday = showmonthfirstday ()
Return new date (monthfirstday. getyear (), monthfirstday. getmonth () + 1, 1)
}
// Last day of next month
Function shownextlastday ()
{
VaR monthfirstday = showmonthfirstday ()
Return new date (monthfirstday. getyear (), monthfirstday. getmonth () + 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 = showpreviusfirstday ();
Document. All. datedate2.value = showpreviuslastday ();
}
If (num = 5 ){
Document. All. datedate. value = shownextfirstday ();
Document. All. datedate2.value = shownextlastday ();
}
If (num = 6 ){
Document. All. datedate. value = showpreviusfirstweekday ();
Document. All. datedate2.value = showpreviuslastweekday ();
}
If (num = 7 ){
Document. All. datedate. value = shownextfirstweekday ();
Document. All. datedate2.value = shownextlastweekday ();
}
If (num = 8 ){
Document. All. datedate. value = showpreviusday ();
Document. All. datedate2.value = showpreviusday ();
}
If (num = 9 ){
Document. All. datedate. value = shownextday ();
Document. All. datedate2.value = shownextday ();
}
}

</SCRIPT>
<Input name = datedate type = text>-> <input name = datedate2 type = text>
& Nbsp; <input name = Haha type = button value = "last month" onclick = setdate (4)> & nbsp;
& Nbsp; <input name = Haha type = button value = "this month" onclick = setdate (1)> & nbsp;
<Input name = Haha type = button value = "next month, January" onclick = setdate (5)> & nbsp;
<Input name = Haha type = button value = "previous week" onclick = setdate (6)> & nbsp;
<Input name = Haha type = button value = "this week" onclick = setdate (2)> & nbsp;
<Input name = Haha type = button value = "next week" onclick = setdate (7)> & nbsp;
<Input name = Haha type = button value = "Last Day" onclick = setdate (8)> & nbsp;
<Input name = Haha type = button value = "today" onclick = setdate (3)> & nbsp;
<Input name = Haha type = button value = "next day" onclick = setdate (9)>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.