Converting MS Active Directory time in human readable format with Groovy
The Problem: medieval time in MS Active Directory
Time and date in Microsofts Active Directory is stored as the number of 100
nanosecond intervals since 1.1.1601. I had to know quickly when was the
last time a user changed his or her password. I got the pwdLastSet date from the LDAP
entry which was 128315688163006928. But I prefer a human readable information since I'm no cyborg.
Groovy to the rescue
But my newly acquired knowledge in Groovy had waited for a chance like
this! So I put together a small script roughly around the idea to use some Java
instance of GregorianCalendar or Date because the whole know-how about leap years is embedded in there. Any suggestions are welcome because I like to learn.
def pwdLastSet = 128315688163006928L
def sylvester1601 = (new GregorianCalendar(1601,1,1)).getTimeInMillis()
def sylvester1970 = (new GregorianCalendar(1970,1,1)).getTimeInMillis()
def diff100Nano = (sylvester1970 - sylvester1601) * 10000
def mSecSince1970 = (pwdLastSet - diff100Nano) / 10000
def pwdLastSetDate = new Date(mSecSince1970.toLong())
println pwdLastSetDate
The Output of this script is:
Tue Aug 14 14:40:16 CEST 2007
which is much better, thank you Groovy!
