Convert Windows timestamp to date using PHP on Linux box

I have an intranet running in a linux box that authenticates with Active Directory in a windows window using LDAP via PHP.

I can get the user entry from AD using LDAP and access the latest login date from the php array, for example:

echo $adAccount['lastlogontimestamp'][0]; // returns something like 129802528752492619

If it were 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, if possible, from a Linux window?

+5
source share
2 answers

this, Windows 100 1 1601 . unix, :

tUnix = tWindow/(10*1000*1000)-11644473600;

10*1000*1000, 1- 1601 , 11644473600, 1601 1970 ( unix).

, PHP:

date("d-m-Y H:i:s", $lastlogontimestamp/10000000-11644473600);

EDIT: , , . Java:

Calendar date1 = Calendar.getInstance(); date1.set(1601, 1, 1);
Calendar date2 = Calendar.getInstance(); date2.set(1970, 1, 1);
long dt = date2.getTimeInMillis() - date1.getTimeInMillis();
System.out.println(String.format("%f", dt / 1000.0)); // prints "11644473600.000000"

SO: Unix/Linux Windows .

+10

, nano seconds , 10000000, 1601-01-01 and 1970-01-01, Windows 1601-01-01

function convertWindowsTimestamp($wintime) {
   return $wintime / 10000000 - 11644477200;
}

$lastlogontimestamp = convertWindowsTimestamp("129802528752492619");
$date = date("d-m-Y H:i:s", $lastlogontimestamp);
var_dump($date);

string '30-04-2012 10:47:55' (length=19)
+3

All Articles