Convert LDAP AccountExpires to DateTime in C#

2019-03-15 04:46发布

I want to convert 18 digit string from LDAP AccountExpires to Normal Date Time Format.

129508380000000000 >> May 26 2011

I got the above conversion from using the following link.

http://www.chrisnowell.com/information_security_tools/date_converter/Windows_active_directory_date_converter.asp?pwdLastSet,%20accountExpires,%20lastLogonTimestamp,%20lastLogon,%20and%20badPasswordTime

I tried to convert by using DateTime.Parse or Convert.ToDateTime. But no success.

Anyone know how to convert it? Thanks very much.

标签: c# datetime ldap
7条回答
SAY GOODBYE
2楼-- · 2019-03-15 05:39

You can use the FromFileTime method on the DateTime class, but watch out, when this field is set to not expire, it comes back as the Int64.MaxValue and doesn't work with either of these methods.

Int64 accountExpires = 129508380000000000;

DateTime expireDate = DateTime.MaxValue;

if (!accountExpires.Equals(Int64.MaxValue))
    expireDate = DateTime.FromFileTime(accountExpires);
查看更多
登录 后发表回答