I have an intranet running on a linux box, which authenticates against Active Directory on a Windows box, using LDAP through PHP.
I can retrieve a user’s entry from AD using LDAP and access the last login date from the php array eg:
echo $adAccount['lastlogontimestamp'][0]; // returns something like 129802528752492619
If this was a Unix timestamp I would use the following PHP code to convert to a human readable date:
date("d-m-Y H:i:s", $lastlogontimestamp);
However, this does not work. Does anyone know how I can achieve this or indeed if it is possible to do so from a Linux box?
According to this, the windows timestamp you have there is the number of 100-ns since Jan 1st 1601. Therefore, you could just convert it to a unix timestamp using the following formula:
You divide by
10*1000*1000to convert to seconds since Jan 1st 1601 and then you discount11644473600which is the number of seconds between Jan 1601 and Jan 1970 (unix time).So in PHP:
EDIT: Interestingly, I got a different offset than Baba. I got mine with Java:
According to this SO: Ways to Convert Unix/Linux time to Windows time my offset is correct.