I've got a hex string, 0x63a4b534, I'd like to convert to a human readable date. However, I'm not sure how to do that. I've tried:
new Date("0x63a4b534").toLocaleDateString()
to no avail.
CodePudding user response:
Found an answer and was close. https://stackoverflow.com/a/847196/15018688
new Date("0x63a4b534".toNumber() * 1000).toLocaleDateString()
CodePudding user response:
// eth timestamp is in seconds. this will give you seconds
const timeInSeconds=parseInt('0x63a4b534',16)
// convert to miliseconds
const timeInMiliseconds=timeInSeconds*1000
const currentTime=new Date(timeInMiliseconds).toLocaleDateString()