Current UNIX EPOCH Timestamp

Convert timestamp to local time

How to convert timestamp to local date in JavaScript?

In JavaScript, we can get local date and time directly with the
Date object.

We have to use toLocaleString() method of date object to convert an UNIX timestamp to browser’s local date.

Lets check this conversion with an example.

Create a html file and add below code as script.

const timestamp = 1691674800000;
const date = new Date(timestamp).toLocaleString();
console.log(date); // 10/8/2023, 7:10:00 pm

If we open the file, output will be console logged after conversion.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Timestamp to Local Time Example</title>
  </head>
  <body>

    <p>Output:</p>
    <div id="output" class="output"></div>

    <script>
      const timestamp = 1691674800000;
      const date = new Date(timestamp).toLocaleString();
      document.getElementById("output").textContent = date;
    </script>
  </body>
</html>