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

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


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


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.


from command Shell

[aks@APC ~]$ date -r 1474588800Fri Sep 23 05:30:00 IST 2016[aks@APC ~]$ date -ur 1474588800Fri Sep 23 00:00:00 UTC 2016[aks@APC ~]$ echo "1474588800" | xargs -I {} date -jr {} -uFri Sep 23 00:00:00 UTC 2016