How to convert LDAP timestamp to Unix timestamp

后端 未结 5 2210
南方客
南方客 2020-12-05 14:59

When I retrieve the LDAP attribute \"pwdLastSet\" of an Active Directory using PHP I get a value like 1.29265206716E+17. I know that this value represents the date \"Tue Aug

5条回答
  •  借酒劲吻你
    2020-12-05 15:25

    Rather than ask the same question for another language.

    Python 3:

    from datetime import datetime, timedelta
    
    def ldap2datetime(ts: float):
        return datetime(1601, 1, 1) + timedelta(seconds=ts/10000000)
    
    print(ldap2datetime(132255350424395239).isoformat())
    # 2020-02-07T07:44:02.439524
    

提交回复
热议问题