Skip to content

Instantly share code, notes, and snippets.

@takehiko
Created September 9, 2012 21:38
Show Gist options
  • Save takehiko/3687481 to your computer and use it in GitHub Desktop.
Save takehiko/3687481 to your computer and use it in GitHub Desktop.
Print current time in various formats
function now() {
case ${1:-_} in
-h*|--h*) # now --help
echo usage: now '[date|httpdate|rfc2822|iso8601]' ;;
d*) # now date
LC_ALL=C date ;;
h*) # now httpdate
ruby -e 'require "time"; puts Time.now.httpdate' ;;
i*|x*) # now iso8601, now xmlschema
ruby -e 'require "time"; puts Time.now.iso8601'\(${2:-0}\) ;;
r*) # now rfc2822, now rfc822
ruby -e 'require "time"; puts Time.now.rfc2822' ;;
*) # now
now d
now h
now i
now r ;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment