Created
June 10, 2011 20:51
-
-
Save pmarreck/1019749 to your computer and use it in GitHub Desktop.
Time string formatting
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
class Time | |
def format_compact(precision = :second, inc_utc = true) | |
prec = [:year, :month, :day, :hour, :minute, :second].index precision | |
fmt_a = ["%Y","%m","%d","_%H","%M","%S"][0..prec] | |
fmt = fmt_a.join('') | |
self.strftime("#{fmt}#{'%Z' if inc_utc}") | |
end | |
def format_datestamp(inc_utc = true) | |
self.strftime("%Y%m%d#{'%Z' if inc_utc}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment