Skip to content

Instantly share code, notes, and snippets.

@bordeux
Created September 23, 2022 16:40
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 bordeux/59fe6fa48682c750ed76fcb08019388c to your computer and use it in GitHub Desktop.
Save bordeux/59fe6fa48682c750ed76fcb08019388c to your computer and use it in GitHub Desktop.
Convert INT96 TimeStamp to Date object in NodeJS/JavaScript
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