Created
December 4, 2020 23:52
-
-
Save andreigec/89b7f7468f628a5085d42f47ae20ee13 to your computer and use it in GitHub Desktop.
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
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