bin: now / timestamp
This commit is contained in:
parent
5bebfbcbde
commit
d82fe28a77
2 changed files with 30 additions and 8 deletions
28
bin/now
Executable file
28
bin/now
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
#!/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}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue