The 1.hour.from_now gives UTC time and as I’m GMT +1, I get the same time as Time.now. Maybe an hint on this issue could help? I’m new to Ruby but not to programming so it didn’t puzzled me but as far as the command is concerned, I don’t personaly get the time “1 hour from now”!
This happens because from_now uses Time.current, which does not consider the time zone. Time.now, however, does respect the Time.zone setting. Since @time already is set using Time.now, you can change the code as shown below to correctly show the time one hour from now based on your time zone setting: <%= 1.hour.since(@time) %>
Can someone please explain 1.hour as well ? what does .hour do ? alexander wang fake bags
houris simply a method that takes no parameters, and returns a value which is three thousand six hundred times the value of the original object. In short, it converts a number of hours into a number of seconds. alexander wang donna hobo
To answer your next question,
from_now is a method that takes no parameters, and returns a value which is the result of value of the original object, which is interpreted to be a number of seconds, to the current time.
I accomplished this by using
<%= @time+1.hour %>. Is it preferable to use
<%= 1.hour.since(@time) %>?
- V11: Phillip J Ramey [over 4 years ago]
- V10: Berts Uchla [over 4 years ago]
- V9: Berts Uchla [over 4 years ago]
- V8: Berts Uchla [over 4 years ago]
- V7: Berts Uchla [over 4 years ago]
- V6: Phillip J Ramey [almost 6 years ago]
- V5: Sam Ruby [over 6 years ago]
- V4: Gaurav Kalra [almost 7 years ago]
- V3: Kevin Styles [almost 7 years ago]
- V2: Kevin Styles [almost 7 years ago]