Skip to content

Instantly share code, notes, and snippets.

@AshUK
Created September 29, 2016 14:20
Show Gist options
  • Save AshUK/dd9b1c42a7ceb072b7e0730340a41299 to your computer and use it in GitHub Desktop.
Save AshUK/dd9b1c42a7ceb072b7e0730340a41299 to your computer and use it in GitHub Desktop.
Active Directory - LDAP Time Stamps to JS Date()
function LdapTimeStapToDate(ldapTimeStamp) {
var sec = Math.round(ldapTimeStamp / 10000000);
sec -= 11644473600;
return new Date(sec * 1000);
}
function Ldap2TimeStapToDate(ldap) {
var year = ldap.substr(0, 4);
var month = ldap.substr(4, 2);
var day = ldap.substr(6, 2);
var hour = ldap.substr(8, 2);
var minute = ldap.substr(10, 2);
var second = ldap.substr(12, 2);
return new Date(Date.UTC(year, month - 1, day, hour, minute, second));
}
var lastLogin = LdapTimeStapToDate(parseInt(aduser.lastLogonTimestamp));
var passwordLastSet = LdapTimeStapToDate(parseInt(aduser.pwdLastSet));
var lastUpdated = Ldap2TimeStapToDate(aduser.whenChanged.toString());
var accountCreated = Ldap2TimeStapToDate(aduser.whenCreated.toString());
var inboxCreated = Ldap2TimeStapToDate(aduser.msExchWhenMailboxCreated.toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment