1
0
Fork 0
dotfiles/bin/now
2026-04-11 23:26:56 -04:00

28 lines
595 B
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
style="${1:-iso}"
flags=()
if [[ "${style}" =~ -utc ]]; then
style="${style%-utc}"
flags+=('--utc')
fi
format=''
case "${style}" in
iso) format='--iso-8601=seconds' ;;
date) format='+%Y-%m-%d' ;;
human) format='+%Y-%m-%d %H:%M %z' ;;
unix) format='+%s' ;;
js) format='+%s%3N' ;;
fs) format='+%Y%m%d_%H%M%S' ;;
zone) format='+%z' ;;
*)
>&2 echo "Unknown format: ${style}"
exit 1
;;
esac
exec date "${flags[@]}" "${format}"