简体   繁体   中英

Parse date and use setdate

2015-12-14 this is my date format, do I have to parse this to date format if I want to use setdate?

I want to attach to a click event where user can go to previous and next date.

Yes you need to store this into date object if you want to use setDate method because only date object would have this method an ordinary object will not have that method.

var date=new Date("2015-12-14");
date.setDate(15);

Javascript date setDate() method sets the day of the month for a specified date according to local time.

Expected values are 1-31, but other values are allowed:

  • 0 will result in the last day of the previous month
  • -1 will result in the day before the last day of the previous month

If the month has 31 days:

  • 32 will result in the first day of the next month

If the month has 30 days:

  • 32 will result in the second day of the next month

 var dt = new Date("2015-12-14"); dt.setDate(33); document.getElementById("demo").innerHTML = dt; 
 <p id="demo"></p> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM