Created
October 25, 2012 23:13
-
-
Save jeremywrowe/3956057 to your computer and use it in GitHub Desktop.
a little reminder about rails time helpers :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'colorize' | |
puts <<-HDOC | |
#{"2.hours.ago".green} # => Fri, 02 Mar 2012 14:02:42 CET +01:00 | |
#{"1.day.from_now".green} # => Fri, 02 Mar 2012 22:04:47 JST +09:00 | |
#{"Date.today.to_time_in_current_zone".green} # => Fri, 02 Mar 2012 00:00:00 JST +09:00 | |
#{"Time.zone.parse(\"2012-03-02 16:05:37\")".green} # => Fri, 02 Mar 2012 16:05:37 JST +09:00 | |
#{"Time.zone.now".green} # => Sat, 03 Mar 2012 00:07:37 JST +09:00 | |
#{"Time.zone.today".green} # If you really can't have a Time or DateTime for some reason | |
#{"Time.zone.now.utc.iso8601".green} # "When supliyng an API (you can actually skip .zone here, but I find it better to always use it, than miss it when it's needed) | |
#{"Time.strptime(time_string, '%Y-%m-%dT%H:%M:%S%z').in_time_zone(Time.zone)".green} # If you can't use parse | |
HDOC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is taken from the "do's" of http://www.elabs.se/blog/36-working-with-time-zones-in-ruby-on-rails