Rails timezones difference
April 9, 2015
- In Rails, Time.zone refers to the Rails (not system) timezone, set by config.time_zone (typically in application.rb)
- DateTime and Time are not otherwise Rails aware, therefore, DateTime.now and Time.now both return times in the system timezone.
1.month.agoand similar methods use the Rails timezone, but DateTime.now.last_month uses the system timezone
- When retrieving things from ActiveRecord, they will be timezoned to the Rails timezone, so Product.first.created_at will give you a time in the Rails timezone (not the system timezone)
So, don't mix Rails timezone methods like “1.month.ago” with system timezone methods like “DateTime.now.last_month”