I want to store, retrieve and handle all times inside my app in just one Timezone. => "New Delhi" for that I''ve set in my application.rb file, config.time_zone = "New Delhi" When i create a record like Event.create(:when => DateTime.new(2011, 5, 7, 16, 0, 0)) it creates an event record in my mysql db (local) with "when" field as "2011-05-07 16:00:00" but when I go to console and retrieve the event date like>> Event.first.when >> Sat, 07 May 2011 21:30:00 IST +05:30It should have given me this instead...>> Sat, 07 May 2011 16:00:00 IST +05:30But when I ask for rails about the timezone in console, it gives me this>> Time.zone >> (GMT+05:30) New DelhiAm I missing something for configuration? I am not able to understand Timezone and its settings concept in rails3.0. I find very little documentation or text on this subject in internet.. Can you please help me understand the concept here... :) thanks fellow rubyist.. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 3 April 2011 06:50, Lucky Dev <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I want to store, retrieve and handle all times inside my app in just one > Timezone. => "New Delhi" > > for that I''ve set in my application.rb file, > > config.time_zone = "New Delhi" > > When i create a record like > > Event.create(:when => DateTime.new(2011, 5, 7, 16, 0, 0))I *think* that DateTime.new defaults to UTC rather than using the current timezone. If you want DateTime.new to use the value specified in config.time_zone then I *think* you have use in_time_zone, see http://api.rubyonrails.org/classes/DateTime.html#method-i-in_time_zone. I prefer to use Time rather than DateTime, then you can use Time.local to create the time.> > it creates an event record in my mysql db (local) with "when" field as > "2011-05-07 16:00:00"Values in the db are always in UTC, whatever timezone is specified so that is correct, given that DateTime.new will have created it in UTC> > but when I go to console and retrieve the event date like >>> Event.first.when >>> Sat, 07 May 2011 21:30:00 IST +05:30Again that is consistent with the value in the db, which is in UTC Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Maybe Matching Threads
- TimeZone daylight savings time problems
- Some timezone trouble involving tzinfo and postgresql
- Introduction & time_zone_select with mapped TimeZone question
- Time zone mapping from TimeZone to TZInfo::Timezone
- TimeZone, TZInfo, daylight savings, and composed_of