Skip to content

Instantly share code, notes, and snippets.

@forthxu
Forked from benwei/date_convert_osx_example.sh
Created September 7, 2022 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forthxu/0a9bb0084b4ea1b91e67533a5b50da62 to your computer and use it in GitHub Desktop.
Save forthxu/0a9bb0084b4ea1b91e67533a5b50da62 to your computer and use it in GitHub Desktop.
MacOS convert timestamp by date command with GNU bash
#!/bin/bash
# author: terry, ben
# tested GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14)
# FYR (for Mac OS, may need some change for linux)
# second -> ISO8601
date -u -r 1453951368 +%FT%TZ
## ouptput: 2016-01-28T03:22:48Z
# ISO8601 -> second
date -ju -f "%FT%TZ" 2016-01-28T03:22:48Z +%s
## output: 1453951368
# current time -> ISO8601
date -u +%FT%TZ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment