Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Rails, what's the nicest way to create a specific time (not now) in a particular time zone?

Here's one way, but it's can you think of a nicer or more 'railsy' method?

>> Time.use_zone('Sydney'){ Time.zone.parse('2011-04-12 2pm') } => Tue, 12 Apr 2011 14:00:00 EST +10:00 
like image 388
Gabe Hollombe Avatar asked May 17 '11 04:05

Gabe Hollombe


1 Answers

I think you're looking for

Time.find_zone('Alaska').local(2011,1,1) => Sat, 01 Jan 2011 00:00:00 AKST -09:00  Time.find_zone('Amsterdam').local(2011,1,1) => Sat, 01 Jan 2011 00:00:00 CET +01:00   Time.find_zone('Sydney').local(2011,1,1) => Sat, 01 Jan 2011 00:00:00 EST +11:00    Time.find_zone('Wellington').local(2011,1,1) => Sat, 01 Jan 2011 00:00:00 NZDT +13:00 

This also works with parse

Time.find_zone('Sydney').parse('2011-04-12 2pm') => Tue, 12 Apr 2011 14:00:00 EST +10:00  
like image 185
toxaq Avatar answered Oct 02 '22 05:10

toxaq