/ Javascript

Win32 Epoch oh why, Win32 epoch to Unix Epoch JS

Recently I have been doing some AD(Active Directory) integration and I cam across the pwdLastSet variable that is on every user object.

This item is stored in a 8 byte long value in the following format: number of 100 nanosecond intervals since January 1, 1601 (UTC)

It is a bit irritating to deal with since there were no easy ways in getting a usable date from it. I ended up changing it from that to good old unix epoch.

// let unixOffset = (((1970-1601) * 365) - 3 + Math.round((1970-1601)/4)) * 86400;
let unixOffset = 11644473600; // Unix offset
let lastSet = adUserObject.pwdLastSet;
let lastSet_ms = Math.round(((lastSet/10000000)-unixOffset)*1000);

So the above code should give you the unix epoch format from the win32 epoch format. Still don't understand the requirement of storing this kind of data to the correct 100th nano second.