---
title: "JavaScript Date Object"  
description: "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."  
author: "Danish Khan"  
published: 2012-10-11  
updated: 2019-11-25  
canonical: https://www.mindstick.com/articles/1041/javascript-date-object  
category: "javascript"  
tags: ["javascript"]  
reading_time: 4 minutes  

---

# JavaScript Date Object

##### Introduction:

In this [article](https://yourviews.mindstick.com/view/81489/kashmir-now-after-an-year-of-abrogation-of-article-370) 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](https://www.mindstick.com/forum/160723/factorial-calculation) on [timestamp](https://www.mindstick.com/interview/626/what-is-the-physical-storage-length-of-each-of-the-following-db2-data-types-date-time-timestamp) then we need a date object. The Java Script simply accesses the [system clock](https://answers.mindstick.com/qa/97175/what-do-you-understand-by-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 |
| --- | --- |
|  |  |
| getDate() | It returns the day of the month. |
| getDay() | It returns the [day of the week](https://answers.mindstick.com/qa/96542/which-function-is-used-to-determine-the-day-of-the-week-for-a-date-in-excel-give-example). |
| getFullYear() | It returns the year. |
| getHours() | It will return the hours. |
| getMilliseconds() | It will return the milliseconds from 0-999. |
| getMinutes() | It will return the [minutes](https://yourviews.mindstick.com/story/1139/6-ways-to-boost-your-energy-in-10-minutes-or-less) from 0-59. |
| getMonth() | It will return the current month from 0-11. |
| getSeconds() | It returns the seconds from 0-59. |
| setDate() | It sets the day of the month to the date object. |
| setFullYear() | It sets the year of a date object. |
| setMonth() | It set the month of a date object. |
| setHours() | It set the hours to the date object. |
| setMinutes | It will set the minutes to the date object. |
| setSeconds() | It will set the seconds of a date object. |
| toDateString() | It returns the Date portion of the date as human readable form. |
| toTimeString() | It returns the time portion of a date as human readable form. |
| [toString](https://www.mindstick.com/interview/2259/what-is-the-difference-between-tostring-convert-tostring)() | It returns the string representation of a date object. |
| valueOf() | It returns the primitive value of a Date object. |
| ## Date [Static Methods](https://www.mindstick.com/forum/161339/static-methods-in-python) |  |
| Date.parse() | Parses a string representation of a date and time and returns the [internal](https://www.mindstick.com/interview/773/describe-the-accessibility-modifier-protected-internal) millisecond representation of that date. |
| Date.UTC() | Returns the millisecond representation of the specified UTC date and time. |

##### Get current Date:

```
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <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 />");
        }
    </script>
</head>

<body onload="getTodayDate()">
</body>
</html>
```

Output :

![JavaScript Date Object](https://www.mindstick.com/mindstickarticle/e7da9c53-b595-4beb-bd60-56112e0c1088/images/c5b8aa1a-277d-4e64-839f-9aa9b0801fe9.png)\

In this example we have added 1 to month because we have to correct the [problem](https://yourviews.mindstick.com/view/81709/why-china-has-problem-with-norway-in-noble-prize-awarding) of being January 0 and December 11.

##### Get Current Time:

```
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <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 />");
        }
    </script>
</head>
<body onload="getTime()">
</body>
</html>
 
 Output:
JavaScript Date Object Conclusion:Through this article we came to know about the date object and how to use it in Java Script.
```

---

Original Source: https://www.mindstick.com/articles/1041/javascript-date-object

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
