Convert unix epoch time to human readable date on Mac OSX - BSD

To convert a UNIX epoch time with OS X date, use

date -j -f %s 123439819723

The -j prevents date from trying to set the system clock, and -f specifies the input format. You can add +<whatever> to set the output format, as with GNU date.


Here you go:

# date -r 123439819723 '+%m/%d/%Y:%H:%M:%S'
08/26/5881:17:48:43

In a bash script you could have something like this:

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
  dayOfWeek=$(date --date @1599032939 +"%A")
  dateString=$(date --date @1599032939 +"%m/%d/%Y:%H:%M:%S")
elif [[ "$OSTYPE" == "darwin"* ]]; then
  dayOfWeek=$(date -r 1599032939 +%A)
  dateString=$(date -r 1599032939 +%m/%d/%Y:%H:%M:%S)
fi