Skip to content

Instantly share code, notes, and snippets.

@ruskotron
Last active December 21, 2015 09:09
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 ruskotron/6283300 to your computer and use it in GitHub Desktop.
Save ruskotron/6283300 to your computer and use it in GitHub Desktop.
So imagine you have an arbitrary time system in place, where you define time as a number of minutes from a particular date (beginning of your "epoch"), or days from that particular date. If you ever needed to convert such dates to a sensible format, commands such as these could be useful to you. Just add to your environment (e.g. ".bashrc") e.g.…
# set base of 'my' epoch (here it's the start of the 21st century)
export MY_EPOCH=$(expr $(date --date="2000/01/01 00:00:00" +%s))
# format date and time, as expressed in minutes from start of 'my' epoch
function strftime_my {
date --date="@$(expr $MY_EPOCH + \( $1 \* 60 \) )"
}
# format date, as expressed in days from start of 'my' epoch
function strfdate_my {
date --date="@$(expr $MY_EPOCH + \( $1 \* 60 \* 60 \* 24 \) )" +"%a, %b %d, %Y"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment