Skip to content

Instantly share code, notes, and snippets.

@saumas
Created October 15, 2025 12:47
Show Gist options
  • Select an option

  • Save saumas/055dadfc8ce99eb86ef9f98d77afab83 to your computer and use it in GitHub Desktop.

Select an option

Save saumas/055dadfc8ce99eb86ef9f98d77afab83 to your computer and use it in GitHub Desktop.
Discord Timestamp Utility
# Discord timestamp helper: dt <datetime> [style]
# datetime examples: 2025-10-15T13:00Z | 2025-10-15T13:00+0000 | unix-epoch | "now"
# style: F f t T d D R (default: F)
dt() {
local input="$1"
local style="${2:-F}"
local epoch=""
local out=""
if [[ -z "$input" ]]; then
echo "Usage: dt <datetime> [F|f|t|T|d|D|R]" >&2
return 1
fi
if [[ ! "$style" =~ ^[FftTdDR]$ ]]; then
echo "Invalid style '$style'. Use one of: F f t T d D R" >&2
return 2
fi
# Special keyword
if [[ "$input" == "now" ]]; then
epoch="$(date +%s)"
else
# Try a few common formats (macOS/BSD date)
local fmts=(
"%Y-%m-%dT%H:%MZ" # 2025-10-15T13:00Z
"%Y-%m-%dT%H:%M%z" # 2025-10-15T13:00+0000 or +01:00 (if no colon, still fine)
"%Y-%m-%d %H:%M %z" # "2025-10-15 13:00 +0000"
"%s" # unix epoch seconds
)
for f in "${fmts[@]}"; do
if epoch_try="$(date -j -f "$f" "$input" "+%s" 2>/dev/null)"; then
epoch="$epoch_try"
break
fi
done
fi
if [[ -z "$epoch" ]]; then
echo "Could not parse '$input'. Try ISO-8601 UTC like 2025-10-15T13:00Z" >&2
return 3
fi
out="<t:${epoch}:${style}>"
printf "%s\n" "$out" | pbcopy # copy to clipboard
printf "%s\n" "$out" # also print to terminal
}
# Optional: tiny completion for the style arg
_dt_styles=(
F f t T d D R
)
compdef '_arguments "1:datetime" "2:->style"; case $state in (style) _values "style" ${_dt_styles[@]} ;; esac' dt

Discord Timestamp Utility

This is a tiny zsh function that:

  • accepts an ISO 8601 UTC like 2025-10-15T13:00Z (and a few other common inputs),
  • lets you pick the Discord style (F, f, t, T, d, D, R),
  • echoes the result and copies it to the clipboard,
  • is callable as dt 2025-10-15T13:00Z.

Drop this into your ~/.zshrc and reload with source ~/.zshrc. Use it like this:

dt 2025-10-15T13:00Z
dt 2025-10-15T13:00Z R
dt now T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment