Created
September 23, 2022 16:40
-
-
Save bordeux/59fe6fa48682c750ed76fcb08019388c to your computer and use it in GitHub Desktop.
Convert INT96 TimeStamp to Date object in NodeJS/JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int96ToDate = value => { | |
const linuxEpoch = 2_440_588; | |
const bigInt = BigInt(value); | |
const julianCalendarDays = Number(bigInt >> BigInt(8 * 8)); | |
const time = Number( | |
BigInt(bigInt & BigInt('0xFFFFFFFFFFFFFFFF')) / BigInt(1_000_000) | |
); | |
const date = new Date(); | |
date.setUTCFullYear(1970, 0, 1); | |
date.setUTCHours(0, 0, 0, 0); | |
date.setUTCDate(1 + julianCalendarDays - linuxEpoch); | |
date.setUTCMilliseconds(time); | |
return date; | |
}; | |
int96ToDate(4.5376149622786669704411136e25).toISOString(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment