How to use Date in JavaScript

In this article I am going to explain about JavaScript Date object.
  • 2009

Java Script Date object

JavaScript Date object referee to complete Date object reference of the Date. In Date object all properties and method can be use with Date and Time. Date object contain complete information about Date and Time.  Date object are created with Date() constructor.

There are four way by which can identified Date and Time

  • New Date() - Current Date and time.
  • New Date(milliseconds) - Display Date and time in millisecond.
  • New Date(dateString) - Display Date and time in String  format.
  • New Date(year, month, day, hours, minutes, seconds, milliseconds) - Display Date time with brief description.

Example

In following Example we will Display Current Date and Time

<html>

<head>

    <script type="text/javascript">

        function test() {

            var myDate = new Date();

            alert(myDate);

        }

    </script>

</head>

<body>

    <button onclick="test()">

        click</button>

</body>

</html>

Output

 time.gif

Further Readings
 
You may also want to read these related articles: here
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.