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 datetime
s not in time zone of user set like:
time.zone = "pacific time (us & canada)"
how parse above datetime
s 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
Post a Comment