Skip to content

Instantly share code, notes, and snippets.

@danieldogeanu
Created October 31, 2020 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieldogeanu/76f7fd5830852287291d0bac21a0c725 to your computer and use it in GitHub Desktop.
Save danieldogeanu/76f7fd5830852287291d0bac21a0c725 to your computer and use it in GitHub Desktop.
How to convert a unix timestamp from a string to a number, in JavaScript, without losing precision.

How to convert a unix timestamp from a string to a number, in JavaScript, without losing precision:

const stringTimestamp = '1603767190'; // Unix Timestamp
const numberTimestamp = (+ new Date(stringTimestamp * 1000)) / 1000;

console.log(numberTimestamp); // 1603767190
console.log(typeof numberTimestamp); // number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment