i am confused as to why i get different timestamps for the same date in ruby and javascript.
In ruby
> ruby_date = Date.new(2012,1,1)
> ruby_date.to_time.utc.to_i
=> 1325368800
In jquery
<script type="text/javascript">
var jquery_date = Date.UTC(2012,1,1);
document.write(jquery_date);
</script>
returns 1328054400000.
Why is there a difference in timestamps. Please explain. I am looking for the number of seconds from epoch. thank you
You did not pass a time value to the date object. Both implementations are assuming a different time of the specified day:
Note, that i removed the last 3 digits of the Javascript timestamp because they are stored in milliseconds (thanks rjz).
Mark Rushakoff explained the month gap in his answer.