LDAP Timestamp to Unix Timestamp

When requesting modifyTimestamp or createTimestamp from openLDAP, you get times in format like this one 20081016115136Z. The following code convert to unix timestamp :

/* Pretty straigtforward but it should be enough */
function ldapTimeToUnixTime($ldapTime) {
        $unixTime = 0;
        /* LDAP time is assumed to start with "YYYYMMDDhhmmss" and to be in a 
         * Greenwith Meantime format.
         */
        $pat = '/^([0-9]{4,4})([0-9]{2,2})([0-9]{2,2})([0-9]{2,2})([0-9]{2,2})' .
        '([0-9]{2,2}).*/';
 
        if(preg_match($pat, $ldapTime, $matches) > 0) {
                $unixTime = gmmktime($matches[4], $matches[5], $matches[6],
                  $matches[2], $matches[3], $matches[1]);
        }
        return $unixTime;
}
 
php/ldaptimetounixtime.txt · Last modified: 2009/09/09 13:22 by tchetch
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Debian Driven by DokuWiki