-4

How convert PST Unix timestamp to UTC and then to any custom time zone (GMT+2, ...) ? Please provide solution in javascript or nodejs lib (momentjs)

Oleg Dats
  • 3,307
  • 8
  • 32
  • 61

1 Answers1

1

Unix timestamps are automatically in GMT, since they are defined as number of seconds since 00:00 on 1st January 1970 GMT. You can create a date object from a timestamp via new Date(timestamp) and you can then use the Date methods to format it. Simple math can be used to move between time zones by simply subtracting the number of hours difference.

Benjie
  • 7,063
  • 4
  • 24
  • 43
  • I have timestamp in Pacific timezone. It can be PST or PDT. How to know what value I need to subtract ? – Oleg Dats Apr 03 '12 at 13:28
  • "Simple math can be used to move between time zones by simply subtracting the number of hours difference." => not that simple, if you want to account for DST. Same question [here](http://stackoverflow.com/questions/10615828/how-to-use-timezone-offset-in-nodejs), but expressed better. – Laurent Couvidou May 30 '12 at 23:27