Reputation: 2520
I have the following method
<%= message.created_at.strftime("%H:%M") %>
that currently returns 21:00
I need to display a Europe/Kiev time zone which is 3 hours ahead than usual Greenwich's time zone. How do I set it in the method input?
Upvotes: 2
Views: 701
Reputation: 504
You can use a beautiful gem named "local_time". It takes care of local rendering of the time in your views. It has very nice documentation as well. Visit https://github.com/basecamp/local_time
Upvotes: 2
Reputation: 310
If you stored time in your database in UTC than that time will always be in UTC when you fetch it. You need to display it according to user's local time zone. You have to do that using JavaScript, check this article.
Or if you need just Kiev time zone and nothing else you can do something like this:
<%= message.created_at.in_time_zone('Europe/Kiev').strftime("%H:%M") %>
Upvotes: 1