0

This is the timestamp I have: 5fb6995

When I do new Date('5fb6995') Invalid Date gets returned. But when I try converting it online in an online converter, everything works. Why doesn't this work and how can I make it work?

Filip
  • 855
  • 2
  • 18
  • 38

2 Answers2

2

You can convert your hexadecimal timestamp to decimal with parseInt and radix 16.

However your timestamp is in hours or something

const ts = parseInt("5fb6995",16); 
console.log(new Date(ts)); // 1970
console.log(new Date(ts*1000)); // still 1973 (Unix TSs are normally in seconds since Epoch - 1970/01/01)

// perhaps you want hh-mm-ss from that UNIX timestamp:

console.log(
  new Date(ts * 1000).toISOString().slice(11,-5)
)
mplungjan
  • 169,008
  • 28
  • 173
  • 236
0

your string 5fb6995 is in hexadecimal base, you need to first convert it to decimal:

new Date(parseInt("5fb6995", 16));
Moshezauros
  • 2,493
  • 1
  • 11
  • 15