Convert UNIX Epoch into Standard Date/Time


Found at Erik's Lab, I found this subroutine while building a script that needed to convert between date/time formats. To use it, just name the UNIX epoch value (it will be a string of numbers like "1207324439") as a variable called "epochseconds" and pass it through the subroutine. For example, you could call the handler like this: set epochseconds to "1207324439" set convertedDate to my epoch2datetime(epochseconds) This would result in a value of "Friday, April 4, 2008 12:00:00 AM" being assigned to the variable called convertedDate.

The Code

on epoch2datetime(epochseconds)
    --Found at Erik's Lab (
    set myshell1 to "date -r "
    set myshell2 to " "+%m/%d/%Y %H:%M""
    set theDatetime to do shell script (myshell1 & epochseconds & myshell2)
    return date theDatetime
end epoch2datetime