You could also supply parameters:-
var d = new Date(milliseconds)
var d = new Date(dateString)
var d = new Date(yr_num, mo_num, day_num [, hr_num, min_num,
e.g. var d = new date(2008,7,30) // 30th August 2008
All dates are calculated in milliseconds from 01 January, 1970 00:00:00 Universal Time (UTC) with a day containing 86,400,000 milliseconds.
var theday = d.getDay() invokes a method of the date object which returns an integer (0 for Sunday through 6 for Saturday) representing the day of the week.