Get Time Object at Start of Day in a Particular Time Zone

Blake Taylor picture Blake Taylor · Nov 3, 2011 · Viewed 22.8k times · Source

How can I get a ruby Time object that represents the start of the day on a particular date in a given timezone.

Answer

Timothy Hunkele picture Timothy Hunkele · Nov 3, 2011
date = Date.today

date.to_time.in_time_zone('America/New_York').beginning_of_day

Currently outputs => 2011-11-02 00:00:00 -0400

Time.now.in_time_zone('Asia/Shanghai').beginning_of_day

Currently outputs => 2011-11-03 00:00:00 +0800

date = Date.today

date.to_time.in_time_zone('Asia/Shanghai').beginning_of_day

Currently outputs => 2011-11-02 00:00:00 +0800