0

I know there are numerous ways to go about this, but I'm dealing with date formatted as such:

"2021-01-06T16:24:34Z"

How do I convert this to a timestamp that represent post unix epoch with Javascript?

N8BIZ
  • 151
  • 1
  • 14
  • 3
    Does this answer your question? [Convert normal date to unix timestamp](https://stackoverflow.com/questions/11893083/convert-normal-date-to-unix-timestamp) – Felix G Jan 24 '22 at 23:56

2 Answers2

0

You just need to parse the date, then divide the resulting number by 1000 to have it in seconds.

To parse it, you just need to remove the T and the Z.

let dateString = "2021-01-06T16:24:34Z";

let dateForDateParsing = dateString.replace("T", " ").replace("Z", "");
console.log(dateForDateParsing);

let UnixTimestamp = Math.floor(new Date(dateForDateParsing) / 1000);
console.log(UnixTimestamp);
Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
0
new Date("2021-01-06T16:24:34Z").getTime() / 1000
Binary Brain
  • 1,170
  • 8
  • 20