10

if I trace new Date().toUTCString() I get something like: Fri Aug 12 07:14:06 2011 UTC. perfect. If I trace new Date().getTime() I get some long negative number which is decreasing as I continue to trace it. This is totally unexpected. Obviously my system clock is OK. What gives?

Tom Auger
  • 19,421
  • 22
  • 81
  • 104

2 Answers2

13

new Date().getTime() returns time in milliseconds from January 1, 1970, universal time. It is positive number but I suppose you're using int to store it so Flash Player converts milliseconds to negative as far as it is more than int.MAX_VALUE. Use Number to store the value of new Date().getTime() and it will be positive.

Constantiner
  • 14,231
  • 4
  • 27
  • 34
  • 2
    This is a very good observation. It doesn't explain though why when I `trace(new Date().getTime());` I get a negative number, does it? Or is there some implicit conversion to `int` during the trace's call to `toString()`? – Tom Auger Aug 12 '11 at 23:55
1

What timezone are you in?

Are you by any chance in a time zone which is xxx seconds earlier than Greenwich?

Try setting the timezone to

timeFormat.setTimeZone(TimeZone.getTimeZone("YOUR TIME ZONE HERE"));

slott
  • 3,266
  • 1
  • 35
  • 30