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 ?
- V11: Phillip J Ramey [about 4 years ago]
- V10: Berts Uchla [about 4 years ago]
- V9: Berts Uchla [about 4 years ago]
- V8: Berts Uchla [about 4 years ago]
- V7: Berts Uchla [about 4 years ago]
- V6: Phillip J Ramey [about 5 years ago]
- V5: Sam Ruby [almost 6 years ago]
- V4: Gaurav Kalra [about 6 years ago]
- V3: Kevin Styles [about 6 years ago]
- V2: Kevin Styles [about 6 years ago]