ruby - 为什么rails保存对象时,created_at时间不是当前系统时间?
大家讲道理
大家讲道理 2017-04-24 09:13:29
0
3
684
subject = Subject.new(name:"First Subject", position: 1, visible: true)

irb(main):008:0* subject.save
   (0.2ms)  BEGIN
  SQL (2.8ms)  INSERT INTO `subjects` (`name`, `position`, `visible`, `created_at`, `updated_at`) VALUES ('First Subject', 1, 1, '2016-04-16 01:52:31', '2016-04-16 01:52:31')
   (1.5ms)  COMMIT

irb(main):008:0* subject
=> #<Subject id: 1, name: "First Subject", position: 1, visible: true, created_at: "2016-04-16 01:52:31", updated_at: "2016-04-16 01:52:31">

本来是在10点左右保存的,但是里面的created_at, updated_at时间是1点,不和系统时间一致。

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(3)
左手右手慢动作

config/application.rb

config.active_record.default_timezone = :local  

I don’t quite understand it yet, please refer to https://ruby-china.org/topics/16187

左手右手慢动作

Which time zone is it? Is it Dongba District? Add 8 hours and see what time it is

irb>Time.now
=> 2016-05-12 15:30:14 +0800
Is that so

迷茫

Because you are at GMT+8. Generally, the GMT time is stored in AR.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template