Javascript Date Get Methods

There are different methods for getting information from a date object.


getMonth() method

This method is used to fetch the month(0 to 11) from given Date object. This function does not accept any parameter.

Input:-
 <script>  
    let todayDate = new Date();  
    document.writeln("Today's Date is ", todayDate);   
    let month = todayDate.getMonth();  
    document.writeln("<br/> Month is ", month);
</script>

Output:-


getDate() method

This method is used to fetch the date of a month from a given Date object. This method does not takes any parameter. It is just used along with a Date Object from which we want to fetch the date of the month.

Input:-
 <script>  
    let todayDate = new Date();  
    document.writeln("Today's Date is ", todayDate);   
    let date = todayDate.getDate();  
    document.writeln("<br/> Date is ", date);  
</script>

Output:-


getHours() method

This method is used to return the hours from a given Date object. This method does not accept any parameter.

Input:-
 <script>  
    let todayDate = new Date();  
    document.writeln("Today's Date is ", todayDate);   
    let hour = todayDate.getHours();  
    document.writeln("<br/> Hour is ", hour);
</script>

Output:-


getMinutes() method

This method is used to fetch the minutes from given Date object. This function does not accept any parameter.

It returns the minutes for the given Date Object. Minutes is an integer value ranging from 0 to 59.

Input:-
 <script>  
    let todayDate = new Date();  
    document.writeln("Today's Date is ", todayDate);   
    let minutes = todayDate.getMinutes();  
    document.writeln("<br/> Minute is ", minutes);
</script>

Output:-


getSeconds() method

This method is used to fetch the seconds from given Date object. This function does not accept any parameter. It returns the second for the given date object. Seconds is an integer value ranging from 0 to 59.

Input:-
 <script>  
    let todayDate = new Date();  
    document.writeln("Today's Date is ", todayDate);   
    let seconds = todayDate.getSeconds();  
    document.writeln("<br/> Second is ", seconds);
</script>

Output:-


getMilliseconds() method

This method is used to fetch the milliseconds from a given Date object. This function does not accept any parameter. It returns the millisecond for the given date object. Milliseconds is an integer value ranging from 0 to 999.

Input:-
 <script>  
    let todayDate = new Date();  
    document.writeln("Today's Date is ", todayDate);   
    let milliseconds = todayDate.getMilliseconds();  
    document.writeln("<br/> Millisecond is ", milliseconds);
</script>

Output:-


getDay() method

This method is used to fetch the day of a week(0 to 6) from a given Date object. This function does not accept any parameter. It returns the day of the week for the given date. Day of the week will be returned in the form of integer value ranging from 0 to 6 means 0 for Sunday, 1 for Monday, and so on till 6 for Saturday.

Input:-
 <script>  
    let todayDate = new Date();  
    document.writeln("Today's Date is ", todayDate);   
    let day = todayDate.getDay();  
    document.writeln("<br/> Day is ", day);
</script>

Output:-


getFullYear() method

This method is used to fetch the year from a given Date object. This function does not accept any parameter. It returns the year for the given date.

Input:-
 <script>  
    let todayDate = new Date();  
    document.writeln("Today's Date is ", todayDate);   
    let year = todayDate.getFullYear();  
    document.writeln("<br/> Year is ", year);
</script>

Output:-


getTime() method

This method used to returns the number of milliseconds since 1 January 1970. when a new Date object is created it stores the date and time data when it is created. This method does not accept any parameter.

Input:-
 <script>  
    let todayDate = new Date();  
    document.writeln("Today's Date is ", todayDate);   
    let time = todayDate.getTime();  
    document.writeln("<br/> Time is ", time);
</script>

Output:-