If you want to get βtodayβ in a specific time zone without changing Time.zone , I would do something like fl00r, and Dylan Markow suggested:
Time.now.in_time_zone('Melbourne').to_date
or that:
Time.find_zone!('Melbourne').today
I wrote a small helper method, Date.today_in_zone , which makes it easy to get the βtoday'sβ Date for the time zone:
# Defaults to using Time.zone > Date.today_in_zone => Fri, 26 Oct 2012
I think it reads a little better than Time.find_zone!('Melbourne').today ...
To use it, just drop it into a file, for example, 'lib/date_extensions.rb' and require 'date_extensions' .
class Date def self.today_in_zone(zone = ::Time.zone) ::Time.find_zone!(zone).today end end
Tyler Rick Oct 26 '12 at 18:20 2012-10-26 18:20
source share