Tag: Rails3/タイムゾーン
config.time_zone = 'Tokyo' config.active_record.default_timezone = :local
$ bundle exec rails generate model DemoItems date1:datetime date2:datetime timestamp1:timestamp
CREATE TABLE `demo_items` ( `id` int(11) NOT NULL AUTO_INCREMENT, `date1` datetime DEFAULT NULL, `date2` datetime DEFAULT NULL, `timestamp1` datetime DEFAULT NULL, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB
irb(main):002:0> item = DemoItem.new => #<DemoItem id: nil, date1: nil, date2: nil, timestamp1: nil, created_at: nil, updated_at: nil> irb(main):003:0> item.date1 = Time.now => 2013-08-30 17:43:48 +0900 irb(main):005:0> item.save! (0.2ms) BEGIN SQL (0.4ms) INSERT INTO `demo_items` (`created_at`, `date1`, `date2`, `timestamp1`, `updated_at`) VALUES ('2013-08-30 08:44:03', '2013-08-30 08:43:48', NULL, NULL, '2013-08-30 08:44:03') (0.6ms) COMMIT
irb(main):006:0> item.created_at => Fri, 30 Aug 2013 08:44:03 UTC +00:00 irb(main):007:0> item.date1 => Fri, 30 Aug 2013 08:43:48 UTC +00:00
irb(main):004:0> item.save! (0.1ms) BEGIN SQL (0.3ms) INSERT INTO `demo_items` (`created_at`, `date1`, `date2`, `timestamp1`, `updated_at`) VALUES ('2013-08-30 08:57:30', '2013-08-30 08:57:18', NULL, NULL, '2013-08-30 08:57:30') (0.3ms) COMMIT
irb(main):005:0> item.date1 => Fri, 30 Aug 2013 17:57:18 JST +09:00 irb(main):006:0> item.created_at => Fri, 30 Aug 2013 17:57:30 JST +09:00
irb(main):001:0> item = DemoItem.new => #<DemoItem id: nil, date1: nil, date2: nil, timestamp1: nil, created_at: nil, updated_at: nil> irb(main):002:0> item.date1 = Time.now => 2013-08-30 18:01:24 +0900 irb(main):003:0> item.save! (0.1ms) BEGIN SQL (0.3ms) INSERT INTO `demo_items` (`created_at`, `date1`, `date2`, `timestamp1`, `updated_at`) VALUES ('2013-08-30 18:01:30', '2013-08-30 18:01:24', NULL, NULL, '2013-08-30 18:01:30') (0.3ms) COMMIT => true irb(main):004:0> item.date1 => Fri, 30 Aug 2013 18:01:24 JST +09:00 irb(main):005:0> item.created_at => Fri, 30 Aug 2013 18:01:30 JST +09:00