DEV Community

Discussion on: Dealing with time zones in rails

bizzibody profile image
Ian bradbury • Edited on

Here's a tip to help make working with date/time values super simple.

[a] Always store date/time values in UTC
[b] Use the browser to convert UTC to local and back

The beauty of this solution is that dates will always be accurate. There is no requirement to take day light savings in to account. There is no need to know the time zone of the user. There are no complex time maths to complete not the server.

(And please - always always always run your server to UTC time)

ting682 profile image
Ting Chung Author

Thanks for the feedback, Ian! At the time in my curriculum, I was not familiar with how to use the front-end to get the browser's time. I believe a lot of things can be refactored given that. I also learned that I can simply fetch the UTC time from the back end and do all my manipulation on the front end.