getDate() : Returns the day of the month for the specified Date Object.

getDay() : Returns the day of the week for the specified Date Object.

getHours() : Returns the hour of the specified Date Object.

getMinutes() : Returns the minutes of the specified Date Object.

getMonth() : Returns the month of the specified Date Object.

getSeconds() : Returns the seconds of the specified Date Object.

getTime() : Returns the number of milliseconds since midnight of January 1, 1970 and the specified Date Object.

getFullYear() : Returns the year (four digits) of the specified date, according to local time of specified Date Object.

setDate(integer) : Sets the day of the month for a specified Date Object.

setHours(integer) : Sets the hours for a specified Date Object.

setMonth(integer) : Sets the month for a specified Date Object.

setSeconds(integer) : Sets the seconds for a specified Date Object.

setTime(integer) :Sets a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970

setFullYear(year,month,day) :sets the year (four digits), according to local time of specified Date Object.

Create a Date Object :

Date objects are created with the Date() constructor.

Syntax new Date() //default version, current date and time
new Date(milliseconds) //milliseconds since 1970/01/01
new Date("month day, year [hours:minutes:seconds]") //String Values
new Date(year, month, day[, hours, minutes, seconds]) /Integer ValuesHandling Events:
Example :
                    var today = new Date();
                    var  d1  = new Date(1364810808261);
                    var d2 = new Date("October 02, 2005 11:13:00");
                    var d3 = new Date(79,5,24,11,33,0); 
                    document.write(today+"<br/>");
                    document.write(d1+"<br/>");
                    document.write(d2+"<br/>");  
                    document.write(d3+"<br/>");
    
Output :
o/p - current date such as Mon Apr 01 2013 15:29:11
o/p - Mon Apr 01 2013 15:38:01 GMT+0530 (IST)
o/p - Sun Oct 02 2005 11:13:00 GMT+0530 (IST)
o/p - Sun Jun 24 1979 11:33:00 GMT+0530 (IST)
Example 1 :
                    <script type="text/javascript">
                        newdate = new Date();
                        d = newdate.getDate();
                        m = newdate.getMonth();
                        y = newdate.getFullYear();
                        alert(d + "/" + m + "/" + y);
                        
                   </script>
    
Example 2 :
                 <script type="text/javascript">
                        var d = new Date();
                        d.setDate(15);  // date set to be 15
                        alert(d);
                        d.setMinutes(20); // minute set to be 20
                        alert(d);
                </script>
    
Example 3 :
                    <script type="text/javascript">
                            Xmas95 = new Date("Feb 15, 2009");
                            weekday = Xmas95.getDay();
                            day = Xmas95.getDate();
                            month = Xmas95.getMonth();
                            alert("weekday -"+weekday+"/day -"+day+"/month -"+month);    // o/p - weekday -0/day -15/month -1
                            //---------------------------------------------------------
                            x=new Date();
                            alert(x.getDay());        // o/p - current day from the week. i.e if current day is Monday->1, Tuesday->2
                           // ---------------------------------------------------------
                            b1= new Date("Jan 17, 2009");
                            b2 = new Date(2009,00,17);
                            alert(b1+"---"+b2);        // o/p- Sat Jan 17 2009 00:00:00 GMT+0530 (IST)---Sat Jan 17 2009 00:00:00 GMT+0530 (IST)
                           // ---------------------------------------------------------
                            theDay = new Date("July 27, 2008");
                            theDay.setDate(24);        
                            alert(theDay);       // o/p-  Thu Jul 24 2008 00:00:00 GMT+0530 (IST)  
                    </script>
    
Exercises :
  1. Print today date as DD-MM-YYYY.
After editing Click here:
Output: