How to convert an LDAP timestamp to a Unix timestamp

When I get the LDAP attribute "pwdLastSet" Active Directory using PHP, I get a value like 1.29265206716E + 17. I know that this value represents the date "Tue Aug 17, 2010 2:11:11 PM GMT + 0200".

How can I convert this value to a Unix timestamp in PHP? Thanks for any tips!

+8
php timestamp ldap
source share
5 answers

See here .

Actually it comes down to converting the FILETIME timestamp to a UNIX timestamp:

 $fileTime = "130435290000000000"; $winSecs = (int)($fileTime / 10000000); // divide by 10 000 000 to get seconds $unixTimestamp = ($winSecs - 11644473600); // 1.1.1600 -> 1.1.1970 difference in seconds echo date(DateTime::RFC822, $unixTimestamp); 
+14
source share

There, this page assuming that it is "100 nanosecond units that have passed since 1.1.1601 00:00:00", this may be useful.

EDIT: 1600 "" 1601

+1
source share

@etranger - correction: there should be a timestamp from 1601 instead of 1600. Refer to the official Microsoft website: http://msdn.microsoft.com/en-us/library/ms675243%28v=vs.85%29.aspx

+1
source share
 $dateLargeInt= "1.29265206716E+17"; // nano seconds since jan 1st 1601 $secsAfterADEpoch = $dateLargeInt / (10000000); // seconds since jan 1st 1601 $ADToUnixConvertor=((1970-1601) * 365.242190) * 86400; // unix epoch - AD epoch * number of tropical days * seconds in a day $unixTsLastLogon=intval($secsAfterADEpoch-$ADToUnixConvertor); // unix Timestamp version of AD timestamp $lastlogon=date("dmY", $unixTsLastLogon); // formatted date 

See http://php.net/manual/en/ref.ldap.php for details

0
source share

I think the first step is to understand what LDAP values ​​really mean - once you realize that everything else is easy.

There are several date-related LDAP attributes. pwdLastSet and accountExpires have values, such as 127524839567199000, and when the value has values, such as 20050210223453.0Z - and both values ​​refer to the same date 10-FEB-2005 .

For a simple explanation see http://maxvit.net/convert_ldap_dates

Hope this helps!

-one
source share

Source: https://habr.com/ru/post/650874/


All Articles