How to display the time in user's timezone

后端 未结 8 1215
深忆病人
深忆病人 2020-11-30 05:42

I am using rails 3.0.5 and I have created_at and updated_at stored in UTC. Now I want to display the created_at time in users\' timezone. I believe it is possible to pick us

8条回答
  •  天命终不由人
    2020-11-30 06:10

    If you'd like to convert your date to a specific Timezone:

    deadline.in_time_zone(time_zone)
    

    Here deadline is a date.

    In addition, you can find Universal time through your local machine Timezone plus local time and vice verse, like in Karachi - +05:00, you can simply add it to value in Universal time to find time in your time zone or get Universal time from your local time by subtraction of Timezone difference (05:00 in our case) from your local time

提交回复
热议问题