In this article I am going to explain you about the date object which is used in Java Script. It is a Data type built into the Java Script language.

The date object in Java Script is basically used to work with date and time. A Date object is useful when we want to display a date or we have to perform some sort of calculation on timestamp then we need a date object.  The Java Script simply accesses the system clock to get the date.                                               

Date objects are created with the new Date(), once a date object is created then we can operate a number of methods on it they are simply used to get and set the year, month, day, time and so on.

Date Object Methods


Date Object Methods





 It returns the day of the month.


It returns the day of the week.


It returns the year.


It will return the hours.


It will return the milliseconds from 0-999.


It will return the minutes from 0-59.


It will return the current month from 0-11.


It returns the seconds from 0-59.


It sets the day of the month to the date object.


It sets the year of a date object.


It set the month of a date object.


It set the hours to the date object.


It will set the minutes to the date object.


It will set the seconds of a date object.


It returns the Date portion of the date as human readable form.


It returns the time portion of a date as human readable form.


It returns the string representation of a date object.


It returns the primitive value of a Date object.

Date Static Methods




Parses a string representation of a date and time and returns the internal millisecond representation of that date.


Returns the millisecond representation of the specified UTC date and time.

Get current Date:
<html xmlns="">

    <script type="text/javascript">
        function getTodayDate() {
            var date = new Date();
            var day = date.getDate();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            document.write("Date is: " + date + "<br />");
            document.write("Day is: " + day + "<br />");
            document.write("Year is: " + year + "<br />");
            document.write("Month is: " + month + "<br />");

<body onload="getTodayDate()">

  Output :

JavaScript Date Object

In this example we have added 1 to month because we have to correct the problem of being January 0 and December 11.

Get Current Time:  
<html xmlns="">

    <script type="text/javascript">
        function getTime() {
            var date = new Date();
            var hrs = date.getHours();
            var min = date.getMinutes();
            var sec = date.getSeconds();
            document.write("Hours is: " + hrs + "<br />");
            document.write("Minutes: " + min + "<br />");
            document.write("Sec is: " + sec + "<br />");
<body onload="getTime()">
JavaScript Date Object 
Through this article we came to know about the date object and how to use it in Java Script.
  Modified On Nov-29-2017 03:20:49 PM

Leave Comment