Skip to content

Instantly share code, notes, and snippets.

@jpf
Created May 4, 2009 22:32
Show Gist options
  • Select an option

  • Save jpf/106715 to your computer and use it in GitHub Desktop.

Select an option

Save jpf/106715 to your computer and use it in GitHub Desktop.
#!/bin/bash
# hexdate.sh
# Gives the hexadecmial representation of time_t
# If the hexadecimal representation of time_t is given as an argument, will print the date that time represented.
#
# Joel Franusic, 49ff6dcc
if [ $# -eq 0 ]; then
echo "obase=16;`date +%s`" | bc | tr '[A-Z]' '[a-z]'
else
HEXTIME=$(echo $1 | tr '[a-z]' '[A-Z]')
TIME_T=$(echo "ibase=16; $HEXTIME" | bc)
date -r $TIME_T
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment