I thought the Time object in Ruby on Rails stores the time but when I ran Time.now.beginning_of_day it gives me the date as well. I’m just trying to capture the time and not the date at all. Is there a way to do this? Thanks
I thought the Time object in Ruby on Rails stores the time but when
Share
Yes you have to do Rails Date Formats – strftime
please see this kink http://www.wetware.co.nz/2009/07/rails-date-formats-strftime/
and this link http://apidock.com/ruby/DateTime/strftime
Example:
// in your case, should do it
Time.now.beginning_of_day.strftime(“%I:%M”)
hope it help.
UPDATE: // well for your question on the comment belowWhy is Time storing date information? Shouldn't it just be time?Good point for you question, as
vladrmention it above(I am sure that the group of people who create rails will think very similar to vladr mention above when they gonna design Time object in rail), when you are talking about time, it cannot be help that it will related to the time zone too. In your case you want to use Time.now.beginning_of_day right? I am now in Thailand and assume that you are in America, Time in America is slower than Thailand for 12 hours, so right now in Thailand it’s Tue 10:00 am, then in America should be Mon 10:00 pm, so you use Time.now.beginning_of_day (let use Time.now for more clear picture), so what should be the answer? so that’s why I think the group of people who create rails use UTC+0 as a standard, In your case I recommend using Time.zone.now, and recently I have found some blog with interesting topic, please see http://www.elabs.se/blog/36-working-with-time-zones-in-ruby-on-rails, hope it help. anyone who read this if you feel that something is missing, feel free to edit my answer, thank you very much for you guys :).