Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure rails to serialize datetime to json always in utc?

Is it possible to configure rails to serialize datetime to json always in utc without timezone?

For example: instead "2011-06-15T21:40:05+06:00" i want "2011-06-15T15:40:05+00:00"

like image 329
Alexey Zakharov Avatar asked Nov 13 '22 21:11

Alexey Zakharov


1 Answers

To set the time zone for the entire application add this line to environment.rb

config.time_zone = 'UTC'

To set the time-zone before a render call

Time.zone = 'UTC'    
render 

Note: These instructions pertains to Rails 2.3x

like image 127
Harish Shetty Avatar answered May 25 '23 12:05

Harish Shetty