How to create a Ruby DateTime from existing Time.zone for Rails? -


i have users entering in dates in ruby on rails website. parse dates datetime object like:

date = datetime.new(params[:year].to_i, params[:month].to_i, params[:day].to_i, params[:hour].to_i, params[:minute].to_i) 

or

date = datetime.parse(params[:date]) 

both datetimes not in time zone of user set like:

time.zone = "pacific time (us & canada)" 

how parse above datetimes in right time zone? know datetime.new method has 7th argument time offset. there easy way offset time zone in given time? or should using other datetime?

you can use time.zone.local if set time.zone previously:

user_time = time.zone.local(params[:year].to_i, params[:month].to_i, params[:day].to_i, params[:hour].to_i, params[:minute].to_i, 0) 

have @ activesupport::timewithzone documentation.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -