Latest posts

10/recent/ticker-posts

Javascript Date object's set( ) methods | Javascript Date object and set methods

set() Method : 

The Javascript Date object is used to represent the Date and time. It has one of the method called set( ) is used to set the date to a Date object.
By using this method the user can easily able to set any date and time to a Date object of Javascript.

In this article, we will discuss the set() method of Date objects in JavaScript and how it can be used to modify different date and time values.

Here are some of the most commonly used arguments for the get( ) method :
1. setDate()
2. setFullYear()
3. setHours()
4. setMilliseconds()
5. setMinutes()
6. setMonth()
7. setSeconds()
8. setTime()

1. setFullYear( ):

This method of the Date( ) object is used to set the Year to a specific Date.
Suppose The Date is 
Then we can easily able to set any specific year to the current Date.
Syntax :
obj.setFullYear();

Example :
const d = new Date();
dt = d.setFullYear(2021, 10, 3);
In addition, we can be set the Month and Day using the setFullYear() method.


2. setMonth( ) :

This method of the Date object is used to set the Month of any specified Date or Current Date. It will set the Month of a specified Date in the form of 0 - 11.
January is considered as 0 and the December is regarded as 11. Basically, it set the Index Number to the Month.
Syntax :
obj.setMonth();

Example :
const date = new Date();
dt = date.setMonth(11);


3. setDate() :

This method of the Date object is used to set the Day as a Number of any specified Date. It set a value between 1 - 31. It depends on how many days are present in a Month.
Suppose the Month is February, then It will set the Date between 1 - 28 or 1 - 29.

Syntax : 
obj.setDate();

Example :
const date = new Date();
dt = date.setMonth(10);

4. setHours() :

This method of the Date object is used to set the Hours of any specified Date. It set a value between 0 - 23.
It considers 0 as 12 AM and 23 as 11 PM.

Syntax : 
obj.setHours();

Example :
const date = new Date();
dt = date.setMonth(20);

5. setMinutes() :

This method of the Date object is used to set the Minutes in the form of a String of Current Date. It set the Value Between 0 - 59.
It means, by using this method the user can set the specific minutes to any date.

Syntax :
obj.setMinutes()

Example :
const date = new Date();
dt = date.setMinutes(56);
document.write("Assigned Minute is : "+dt);

6. setSeconds() :

This method of the Date object is used to set the Seconds in the form of a String of Current Date. It set the Value Between 0 - 59.
It means, by using this method the user can set the specific Seconds to any date.

Syntax :
obj.setSeconds();

Example :
const date = new Date();
dt = date.setSeconds(36);
document.write("Assigned Minute is : "+dt);


That's all for Now...!
I hope this article will help you to learn JavaScript Programming More..!

Thank You..!




Also Visit


Post a Comment

0 Comments