Skip to content

Instantly share code, notes, and snippets.

@andreigec
Created December 4, 2020 23:52
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 andreigec/89b7f7468f628a5085d42f47ae20ee13 to your computer and use it in GitHub Desktop.
Save andreigec/89b7f7468f628a5085d42f47ae20ee13 to your computer and use it in GitHub Desktop.
export const CSharpToJs = (ticks: number) => {
// ticks are in nanotime; convert to microtime
const ticksToMicrotime = ticks / 10000;
// ticks are recorded from 1/1/1; get microtime difference from 1/1/1/ to 1/1/1970
const epochMicrotimeDiff = Math.abs(new Date(0, 0, 1).setFullYear(1));
// new date is ticks, converted to microtime, minus difference from epoch microtime
const tickDate = new Date(ticksToMicrotime - epochMicrotimeDiff);
return tickDate;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment