1

Let's suppose I have the following data:

Unix timestamp: 1388935522

User Timezone: America/Los_Angeles

I currently have the following piece of code,

Time.at(1388935522).strftime("%I:%M %P")

which converts the Unix timestamp.

What is the best way to use the "User Timezone" (currently as a "string") to determine the offset (which would be -8:00) and display the time based upon the user's timezone (7:25 am).

Thanks very much!

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
Dodinas
  • 6,705
  • 22
  • 76
  • 108
  • 1
    Have a look here: http://stackoverflow.com/questions/19128436/ruby-converting-utc-to-users-time-zone – vee Jan 05 '14 at 18:11
  • Or also here: http://stackoverflow.com/questions/9962038/how-do-i-calculate-the-offset-in-hours-of-a-given-timezone-from-utc-in-ruby – sameers Jan 05 '14 at 18:18

1 Answers1

0

You have basically two alternatives:

  1. server-side approach
  2. client-side approach using JavaScript

I explained both in this answer no more than a few days ago.

Community
  • 1
  • 1
Simone Carletti
  • 173,507
  • 49
  • 363
  • 364