Last Updated: February 25, 2016
·
1.95K
· pimschaaf

Convert a Unix timestamp to time in Javascript

/**
 * Convert a Unix timestamp to time in Javascript
 * See http://stackoverflow.com/questions/847185/convert-a-unix-timestamp-to-time-in-javascript
 * @param int unix_tm Unix timestamp in seconds from for instance PHP
 * @return date timestamp in milliseconds
 */
function dateFromUnixTimeStamp(unix_tm) {
    return new Date(unix_tm*1000);
}

Courtesy of Aron Rotteveel on Stackoverflow
http://stackoverflow.com/users/11568/aron-rotteveel

Thanks @thajeztah

1 Response
Add your response

I'd remove the interim dt variable, probably no reason to have it. Also, a more descriptive name wouldn't hurt, e.g. dateFromUnixTimeStamp()

over 1 year ago ·