How to Convert a UNIX Timestamp to a Date in JavaScript or Node.js

The UNIX time describes a point in time using an integer value. This integer is the number of seconds since the UNIX epoch. The UNIX epoch is 01 January 1970 at 00:00:00 UTC.

This tutorial shows you how to convert a UNIX timestamp to a JavaScript date instance.

Node.js Series Overview

Convert UNIX Time to a Date in JavaScript

The UNIX time uses seconds to represent a point in time. JavaScript dates work with milliseconds. You can still translate a UNIX timestamp to a JavaScript by translating the given value from seconds to milliseconds:

 * Returns a date instance from the given `unixTimestamp`.
 * @param {Number} unixTimestamp  Number of seconds since Unix epoch
 * @returns {Number}
function toDate (unixTimestamp) {  
  return new Date(
    unixTimestamp * 1000

Enjoy working with UNIX times and JavaScript dates!

Explore the Library

Find interesting tutorials and solutions for your problems.