不同的日期保存到数据库中 - 错误的时区 [英] Different date saved to database - wrong time zone
本文介绍了不同的日期保存到数据库中 - 错误的时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我取的日期从FullCalendar使用Javascript我有以下值:
When I fetch a date from FullCalendar with Javascript I have the following values:
Fri Sep 13 2013 08:30:33 GMT-0400 (EDT)
在我的约会保存到数据库中,我看到,在数据库中有不同的值:
After I save that date to database I see that in database there are different values:
2013-09-13 12:00:00.000000
所以,日期将自动转换为UTC并保存这样到数据库中。如何保存正确的日期存入数据库?我不想硬code吧:)
So, date is automatically converted to UTC and saved like that into database. How to save the correct date into database? I don't want to hardcode it :)
感谢你。
推荐答案
对于您需要定义时区的application.rb中
For that you need to define your time zone in your application.rb
config.time_zone = 'YOUR-TIME-ZONE'
config.active_record.default_timezone = :local
config.active_record.time_zone_aware_attributes = false
这篇关于不同的日期保存到数据库中 - 错误的时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文