1

My backend is currently supplying my frontend with the following information:

time: {
    stamp: '2013-11-03T18:12:39',
    timezone: 'PST'
}

I'm currently using Moment.js to convert the time into a more readable string: 11/03/2013 6:12 PM PST

However, this is not accurate as the original time is in GMT. How can I apply the timezone conversion using the string 'PST'?

Does anyone know of a library that can assist in doing so or will I be required to code a long switch that would look at the string and offset the time from there for all timezones applicable to the application?

Moment.js has a timezone conversion tool, however it uses location information not timezone short forms.

Neil
  • 2,509
  • 7
  • 32
  • 47
  • 2
    [Definitely don't handle the time zones yourself!](http://www.youtube.com/watch?v=-5wpm-gesOY) – Mike Christensen Jan 06 '14 at 18:15
  • 1
    Can't you do the conversion in the backend? – gen_Eric Jan 06 '14 at 18:26
  • Leaning towards suggesting it.. I am not the BE programmer. Is it easier done in .NET that way? – Neil Jan 06 '14 at 18:28
  • @Neil: I don't know .NET, but it might be. – gen_Eric Jan 06 '14 at 18:29
  • 1
    If the backend just serialized `DateTime` objects in JSON correctly, everything would just magically work. The timezone of the server would be taken into account, the time would be serialized across the wire in UTC, and the time would display in JavaScript according to the local timezone. Ask the backend developer(s) to serialize their `DateTime` objects correctly; this is truly not your problem to deal with. – Mike Christensen Jan 06 '14 at 18:54
  • [I think this article will answer your question](http://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript) – Tony Zampogna Mar 19 '14 at 00:40

0 Answers0