Skip to content

Instantly share code, notes, and snippets.

@bryanburgers
Last active May 3, 2024 18:09
Show Gist options
  • Save bryanburgers/55b05686b7fc4ee3c3f6 to your computer and use it in GitHub Desktop.
Save bryanburgers/55b05686b7fc4ee3c3f6 to your computer and use it in GitHub Desktop.
Format the date how I like it, for use in the status bar of tmux
#!/bin/bash
# Format the current date in a way that clearly shows local time and UTC time,
# for use in a tmux status bar.
# Examples:
# tmux-date (with computer set to America/Chicago timezone)
# 2016-01-11 / 08:55 -06:00 / 14:55Z
# TZ="Australia/Victoria" tmux-date
# 2016-01-12 / 01:55 +11:00 / 2016-01-11T14:55Z
localdate=$(date +"%Y-%m-%d")
localtime=$(date +"%H:%M")
localoffset=$(date +"%:z")
utcdate=$(date +"%Y-%m-%d" --utc)
utctime=$(date +"%H:%MZ" --utc)
# If the date in the UTC timezone is the same as it is in the current timezone,
# then displaying the UTC date is just adding clutter. However, if the dates
# differ, then display the date. Having the date displayed will call attention
# to itself that the UTC date and the local date are currently different.
if [[ $utcdate == $localdate ]]; then
utcdatedisplay=""
else
utcdatedisplay="${utcdate}T"
fi
echo "$localdate / $localtime $localoffset / ${utcdatedisplay}${utctime}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment