JavaScript Tutorial

Javascript Date Set Methods

There are different methods which let us set date values for a date object.

setMonth() method

This method is used to set month into a date object which is created using the Date() constructor. It returns the new i.e updated month which is set by setMonth() method.

Input:-

Output:-

setDate() method

This method is used to set date of a month into a date object which are created using date() constructor. This method return the number of milliseconds between the date object and midnight January 1, 1970.

Input:-

Output:-

setHours() method

This method is used to set hours into a date object which is created using the Date() constructor. It returns the new date with updated hour which is set by setHours() method.

Input:-

Output:-

setMinutes() method

This method is used to set minutes into a Date object which is created using Date() constructor. It returns the new date with updated minute which is set by setMinutes() method.

Input:-

Output:-

setSeconds() method

This method is used to set seconds into a Date object which is created using Date() constructor. It returns the new Date with updated second which is set by setSeconds() method.

Input:-

Output:-

setFullYear() method

This method is used to set year into a date object which is created using Date() constructor. It returns the new date with updated year which is set by setFullYear() method.

Input:-

Output:-

 

 

Go back to Previous Course