9.3  Java Script - Date Object

Index Code Tester

OBJECTIVE

DISCUSSION

Date Object 

var dDate = new Date()
alert(dDate)
var dD1 = new Date("October 31, 2003 12:34:00")  //can use this format without specifying time
alert(dD1)
var dD2 = new Date(1994, 0, 22)
alert(dD2)
var dD3 = new Date(2002, 11, 7, 9, 35, 23)
alert(dD3)
var dD4 = new Date(154456) //This is date that is 154456 milliseconds since January 1, 1970
var dD = new Date()
alert(dD)
dD.setYear(2010)  //sets year to 2010
alert(dD)
alert(dD.getDate())  //gets day
alert(dD.getTime())  //# milliseconds since 1970
 

EXERCISES

1.  List the methods associated with the Date object.

2.  Create a page and display the time in the status bar.  Display only the hour and minutes. Do not hard-code the time. 

3.  Write a function that accepts a date object and returns which day of the week it is.  For example, if the date is a 12/4/2003, the function should return Thursday.  Hint, use getDay().

4.  Create a function that accepts 2 dates and returns the number of days between them. Test your function.

5.  Create a function that automatically generates a calender displaying the days in the current month.

LINKS AND HELP

http://www.w3schools.com/js/js_datetime.asp