Convert milliseconds timestamp to date from unix command line

Instead of dropping characters, you could divide by 1000:

awk '{print strftime("%c", ( <timestamp in milliseconds> + 500 ) / 1000 )}'

Or:

date -d @$(  echo "(MilliSecondTimeStamp + 500) / 1000" | bc)

Or (MacOS):

gdate -d @$(  echo "(MilliSecondTimeStamp + 500) / 1000" | bc)

Edit: Adjusted for the quotients instead of division. Edit2: Thx zeekvfu, fixed.


What I have in my bash profile on Mac:

day() {
  date -r $(($1 / 1000))
}

day 1486743904359 returns Fri Feb 10 08:25:04 PST 2017

Tags:

Unix

Date

Awk