I have a problem with passing date from Angular to Rails. In my project i use datetimepicker directive (https://github.com/dalelotts/angular-bootstrap-datetimepicker) which is using moment js. So when i pick the date it looks like "Wed Aug 05 2015 11:55:00 GMT+0300 (EEST)". Then this date is passing to rails api and rails converts it in "2015-08-05T08:55:00.000Z". So i simply need that the time received by rails was 11:55:00 not 08:55:00.
Asked
Active
Viewed 406 times
1 Answers
2
You do need to realize that Wed Aug 05 2015 11:55:00 GMT+0300 is equal to 2015-08-05T08:55:00.000Z and that the later date is a translation to UTC of the first one.
To change the timezone in which Active Record saves in the database, you can use
# application.rb
config config.time_zone = 'Eastern Time (US & Canada)'
config.active_record.default_timezone = :local
Warning! You really should think twice, even thrice, before saving times in the database in a non-UTC format.
Here's how you can find all available timezones
rake:time:all
More information: https://stackoverflow.com/a/32229086/4304188

Community
- 1
- 1

Mihai Dinculescu
- 19,743
- 8
- 55
- 70
-
yes, i already did that but i can't figure why i set config.time_zone to anything and it doesn't make any changes? i set config.time_zone to 'Eastern Time (US & Canada)', 'London', 'Kyiv', 'Moskow' etc. but it is still **2015-08-05T08:55:00.000Z**. What i'm doing wrong? – Anthony Aug 26 '15 at 14:33
-
Even if you set `config config.time_zone`, Active Record still uses UTC by default. `config config.time_zone` affects Rails, not Active Record and not the database. – Mihai Dinculescu Aug 26 '15 at 14:34
-
Have you restarted your server? – Mihai Dinculescu Aug 26 '15 at 14:43
-
Yes, i have restarted my server with every changes. Sorry but actually i don't understand what i shall to do to write the picked date to the database correctly. – Anthony Aug 26 '15 at 14:48
-
The two lines found in my answer should achieve that. – Mihai Dinculescu Aug 26 '15 at 14:49
-
Ok, thnx a lot:) I just confused with all that date formats you know:) i will store dates in database in utc as it is – Anthony Aug 26 '15 at 15:07