我在我的表中有时间列。并在/config/application.rb
上午有以下声明。 config.time_zone = 'Mumbai'
。在Rails中,时间列未显示保存时间的time_zone中的时间?
和IAM节省的时间在数据库中,用下面的查询
punch_rec.check_out = Time.now
punch_rec.save
当i型Time.now在终端它显示以下的时间。
2.2.2 :032 > Time.now
=> 2015-09-28 15:59:06 +0530
当我从数据库检索数据,然后它显示在UTC
time_zone中的时间。正因为如此,我认为时间显示错误。
这些是iam执行的步骤。
2.2.2 :038 > p = PunchInOut.find_by_id("28")
PunchInOut Load (0.3ms) SELECT `punch_in_outs`.* FROM `punch_in_outs` WHERE `punch_in_outs`.`id` = 28 LIMIT 1
=> #<PunchInOut id: 28, employee_id: 3, check_in: nil, check_out: nil, date: "2015-09-28", created_at: "2015-09-28 18:37:24", updated_at: "2015-09-28 10:25:22", shift_id: nil, shift_name: nil>
2.2.2 :039 > p.check_in
=> nil
2.2.2 :040 > Time.now
=> 2015-09-29 00:19:17 +0530
2.2.2 :041 > p.check_in= Time.now
=> 2015-09-29 00:19:33 +0530
2.2.2 :042 > p.save
(0.3ms) BEGIN
SQL (0.7ms) UPDATE `punch_in_outs` SET `check_in` = '2015-09-28 18:49:33', `updated_at` = '2015-09-28 18:49:38' WHERE `punch_in_outs`.`id` = 28
(37.7ms) COMMIT
=> true
2.2.2 :043 > p = PunchInOut.find_by_id("28")
PunchInOut Load (0.6ms) SELECT `punch_in_outs`.* FROM `punch_in_outs` WHERE `punch_in_outs`.`id` = 28 LIMIT 1
=> #<PunchInOut id: 28, employee_id: 3, check_in: "2000-01-01 18:49:33", check_out: nil, date: "2015-09-28", created_at: "2015-09-28 18:37:24", updated_at: "2015-09-28 18:49:38", shift_id: nil, shift_name: nil>
2.2.2 :044 > p.check_in
=> 2000-01-01 18:49:33 UTC
2.2.2 :045 >
我该如何解决这个问题。
Rails的默认保存所有倍到数据库UTC,然后将它们** **显示在适当的时区,被转换的飞行。所以,我希望视图能够显示适当的转换时间。你可以在你的问题中加入以下信息:a)LOCALY你认为'att.check_out'什么时候应该设置为b)什么存储在数据库中,而不是转换它(查看你的数据库终端而不是使用Rails )c)当你执行'<%= att.check_out%>时显示的是什么' –
@MaxWilliams我更新了我的问题。 – John
@MaxWilliams,如果导轨每次保存UTC时间。那么这种说法有什么用处('config.time_zone ='孟买')?它会做什么? – John