Page 159 - DCAP202_Fundamentals of Web Programming
P. 159

Fundamentals of Web Programming




                    Notes          you can let JavaScript create a Date object based on your visitor’s system clock. It is usually best
                                   to let JavaScript simply use the system clock.

                                   Syntax

                                   new  Date(  )
                                   new  Date(milliseconds)
                                   new  Date(datestring)
                                   new  Date(year,month,date[,hour,minute,second,millisecond  ])
                                   The Date object has been created, and now we have a variable that holds the current date! To get
                                   the information we need to print out, we have to utilize some or all of the following functions:
                                      getTime() - Number of milliseconds since 1/1/1970 @ 12:00 AM

                                      getSeconds() - Number of seconds (0-59)
                                      getMinutes() - Number of minutes (0-59)
                                      getHours() - Number of hours (0-23)
                                      getDay() - Day of the week(0-6). 0 = Sunday, ... , 6 = Saturday

                                      getDate() - Day of the month (0-31)
                                      getMonth() - Number of month (0-11)
                                      getFullYear() - The four digit year (1970-9999)


                                          Example:
                                   <h4>It  is  now
                                   <script  type=”text/javascript”>
                                   <!—
                                   var  currentTime  =  new  Date()
                                   var  month  =  currentTime.getMonth()  +  1
                                   var  day  =  currentTime.getDate()
                                   var  year  =  currentTime.getFullYear()
                                   document.write(month  +  “/”  +  day  +  “/”  +  year)
                                   //—>
                                   </script>
                                   </h4>

                                   13.1.2 Creating Arrays and Objects

                                   JavaScript objects are collections of properties and methods. A method is a function that is a
                                   member of an object. A property is a value or set of values (in the form of an array or object) that
                                   is a member of an object. JavaScript supports four kinds of objects: intrinsic objects, objects you
                                   create, host objects, which are provided by the host (such as window and document in Internet
                                   Explorer) and ActiveX objects.
                                   All objects in JavaScript support “expando” properties and methods, or properties that can be
                                   added and removed at run time. These properties and methods can have any name, including
                                   numbers. If the name of the property or method is a simple identifier, it can be written after the
                                   object name with a period, such as:
                                   var  myObj  =  new  Object();
                                   myObj.name  =  “Fred”;
                                   myObj.age  =  42;


          152                               LOVELY PROFESSIONAL UNIVERSITY
   154   155   156   157   158   159   160   161   162   163   164