I configured my time zone to indian time zone in my Rails app by adding this line config.time_zone = 'Mumbai'
to my application.rb
file.
I am having a date time field t.datetime :check_in
in my table. To this check_in
column I am saving the server time like this Person.check_in = DateTime.now
. When I save like this, the time is saving properly, with the time zone configured in the app. after that for some reason when I update like this Person.check_in = "24/08/2015 11:50 AM".to_datetime
it is not saving the time with the time zone I configured. Below is my rails console output:
prashant@prashant-pc:~/client_proj/template$ rails c
Loading development environment (Rails 4.1.5)
2.2.2 :001 > check_in = DateTime.now
=> Mon, 24 Aug 2015 11:41:16 +0530
2.2.2 :003 > "24/08/2015 11:42 PM".to_datetime
=> Mon, 24 Aug 2015 23:42:00 +0000
2.2.2 :004 >