Home > DeveloperSection > Articles > Implementing Date object in Java Script

Implementing Date object in Java Script

JavaScript JavaScript 
0 Comment(s)
 5050  View(s)
Rate this:

Implementing Date object in Java Script

We can use Date () object to manipulate dates in java script. Whenever we want to access current date of the system or want to set new date in java script then we can use appropriate java script method of date function. In this demonstration we learn how to work with function of date object.
Some important function related with date object

Ø  Date ()  --- Date () function return current system date with time.

Ø  toDateString() --- toDateString() function return current date without time.

Ø  getDay() --- getDay() method returns current day of weak.

Ø  getDate() --- getDate() method returns current day of month in numeric.

Ø  getMonth() --- getMonth() method returns current month.

Ø  getFullYear()  --- getFullYear() method return full year.

Ø  setDate()  --- setDate() method is used to set new date of month.

Ø  setMonth () --- setMonth() method is used to set new month.

Ø  setFullYear() --- setFullYear() method is used to set new full year.

Following example demonstrate use of Date object in java script

<html xmlns="http://www.w3.org/1999/xhtml">



    <script type="text/javascript">

        function dateObject() {

            //Displaying current system date and time.

            document.write("Current System Date With Time  :" + Date() + "<br />");

            //Displaying only current system date only.

            var currentDate = new Date();

            document.write("Current System Date Without Time  :  " + currentDate.toDateString() + "<br />");

            //Displaying Current System Day.

            document.write("Current System Day  :  " + currentDate.getDay() + "<br />");

            //Displaying current numeric day

            document.write("Current System Numeric Day  :  " + currentDate.getDate() + "<br />");

            //Display Current Month.

            document.write("Current System Month  :  " + currentDate.getMonth() + "<br />");

            //Displaying Full Year

            document.write("Current Full Year  :  " + currentDate.getFullYear() + "<br />");


                We can also set new date also or new month by addong set prefix in all

                the methods as like setDate(), setMonth() etc..


            //Setting new Date.


            //Setting new month.


            //Setting new year.


            //Viewing new date.

            document.write("New System Date  :  " + currentDate.toDateString());





    <input type="button" value="Click this to view message" onclick="dateObject()" />



Output of the following code snippet is as follows

Date object in Java Script

Date object in Java Script

Don't want to miss updates? Please click the below button!

Follow MindStick