Skip to content

Instantly share code, notes, and snippets.

@pmarreck
Created June 10, 2011 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmarreck/1019749 to your computer and use it in GitHub Desktop.
Save pmarreck/1019749 to your computer and use it in GitHub Desktop.
Time string formatting
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