Why is this returning the 31st instead of the 1st? As I understand it, the UTC method requires 3 parameters ( full year, month, day ), and the day parameter must be an integer between 1 – 31. Because getDate() returns with an integer between 0 and 31, I also suspected 0 would be a possibility.
firstDay = new Date(Date.UTC( 2011 , 7 , 1 )).getDate();
// returns 31 (last day of this month)
Let me clarify and say, this is not a special case. With the day parameter as 2, 3, or 4, this will return 1, 2, 3, and so on.
Your timezone offset is negative so like -4. So 7/1/2011 at 12:00AM minus 4 hours is 6/31/2011 8:00PM. Date.UTC takes additional parameters that you can use to pass hours, minutes, seconds, and milliseconds.
But really, if you don’t want the timezone adjustment use
new Date(year, month, day)