Reputation: 3
I am doing the following:
new Date().setFullYear(2011, 0, 1);
Does this gives me the number of seconds since January 1, 1970?
Upvotes: 0
Views: 92
Reputation: 147363
> new Date().setFullYear(2011, 0, 1);
Does this gives me the number of seconds since January 1, 1970?
No, because the hours, minutes and seconds need to be zeroed too:
x = new Date();
x.setFullYear(2011, 0, 1);
x.setHours(0, 0, 0);
alert(x - 0);
Upvotes: 1
Reputation: 27464
Internally, Javascript stores a date as the number of milliseconds since midnight, January 1, 1970. (Not seconds -- milliseconds.) You can get this number out of the date object with the getTime function.
In practice, the "base date" rarely makes a difference. Usually you use the various Date functions to format the date in a conventional format. You occasionally get differences between two times by using getTime and subtracting one from another.
Upvotes: 0
Reputation: 3079
That just gives you a date object.
Date d = new Date().setFullYear(2011, 0, 1);
d.getSeconds(); //gives you number of seconds for the date you've set (0-59), but not from Jan 1,1970.
Upvotes: 0