Last Updated: February 25, 2016
·
2.258K
· 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 ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside