This method is used to change the date of a Date object. For example :
var date = new Date(); console.log(date); date.setDate(9); console.log(date);
It will print the output like below :
Set the full year in four digits for a date.
var date = new Date(); console.log(date); date.setFullYear(2011); console.log(date);
var date = new Date(); console.log(date); date.setHours(11); console.log(date.toLocaleTimeString());
It changes the local time. So, we are using toLocaleTimeString to print the time in local. The output will be like below :
2019-09-26T15:03:34.645Z 11:33:34 AM
Set the millisecond for a Date. This method changes the local time.
Change the minute for a Date in local time.
Change the month for a Date. As like the other methods, it also works with the local time.
Change the seconds as per the local time.
Change the Date using an unix time, i.e. you can set number of milliseconds since January 1, 1970, 00:00:00 UTC. For prior times, negative number is used.
var date = new Date(); console.log(date); date.setTime(1000); console.log(date);
It will print :
Change the year using 2 or 3 digits as per the local time.
All of these methods work in a same way as like the other local time methods.