I have an application which save datetime using Time.now, but when I retrieves it and compare with Time.now again it not the same format and result in unexpected result.
What should I do to always make this time standard all the time.
Thanks,
I have an application which save datetime using Time.now, but when I retrieves it and compare with Time.now again it not the same format and result in unexpected result.
What should I do to always make this time standard all the time.
Thanks,
Rails treats time in a special way because time zone support in Ruby was deemed insufficient, i.e. Ruby Time instances only work with UTC and ENV['TZ']
A Time object persisted in ActiveRecord will therefore look quite different to the return value of Time.now
. To get on the same page as Rails use Time.zone.now
Favorite thing ever when it comes to time parsing and standardizing values is the Chronic gem. Natural format time parser. Very handy. Saves me from a lot of work trying to write/read time formats correctly for databasing time formats. Maybe not really the solution to the problem, but its worth a look.