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:
If the month has 31 days:
If the month has 30 days:
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.