·  JavaScript – Syntax – Variables – Date/Time

 

- Info:

  - This tutorial shows how to work with strings in JavaScript.

 

- Example:

  - Create D\Temp\JavaScript\Test.html

 

    Test.html

    <script> 

   

      //CREATE.

      now    = new Date();

      date1  = new Date(2012,10,1, 23,45,33,999); //year, month, day, hours, minutes, seconds,   millisec

      console.log(date1);

      //GET. 

      milisec = date1.getDate();

      

      //GET COMPONENTS.

      year        = date1.getYear   () + 1900;    //Year-1900

      month       = date1.getMonth  ();           //[0,11]=[January,December]

      dayOfMonth  = date1.getDate   ();           //[1,31]

      hour        = date1.getHours  ();           //[2,23]

      minutes     = date1.getMinutes();           //[0,59]

      seconds     = date1.getSeconds();           //[0,59]

      

      //CHANGE.

      date1.setDate(date1.getDate()+5);           //Add 5 days.

      

      //DISPLAY.

      document.write(now   + "<br>"); //Sat Feb 18 2012 17:32:41 GMT+0100 (Central Europe  Standard Time)

      document.write(date1 + "<br>"); //Tue Jan 24 2012 23:45:33 GMT+0100 (Central Europe  Standard Time)

      document.write("year       =" + year       + "<br>");

      document.write("month      =" + month      + "<br>");

      document.write("dayOfMonth =" + dayOfMonth + "<br>");

      document.write("hour       =" + hour       + "<br>");

      document.write("minutes    =" + minutes    + "<br>");

      document.write("seconds    =" + seconds    + "<br>");

   

    </script>