Bash convert epoch to date, showing wrong time

bobbyrne01 picture bobbyrne01 · May 1, 2013 · Viewed 76.4k times · Source

How come date is converting to wrong time?

result=$(ls /path/to/file/File.*)
#/path/to/file/File.1361234760790

currentIndexTime=${result##*.}
echo "$currentIndexTime"
#1361234760790

date -d@"$currentIndexTime"
#Tue 24 Oct 45105 10:53:10 PM GMT

Answer

andrewdotn picture andrewdotn · May 1, 2013

This particular timestamp is in milliseconds since the epoch, not the standard seconds since the epoch. Divide by 1000:

$ date -d @1361234760.790
Mon Feb 18 17:46:00 MST 2013