Last active
April 30, 2025 05:08
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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