2018年11月23日 星期五

[C#] How to convert Active Directory pwdLastSet to Date/Time

From https://stackoverflow.com/questions/18614810/how-to-convert-active-directory-pwdlastset-to-date-time

According to the MSDN documentation:
This value is stored as a large integer that represents the number of 100 nanosecond intervals since January 1, 1601 (UTC).
This aligns perfectly with DateTime.FromFileTimeUtcas described here.
And I'm not sure why you feel the need to do the low level manipulation of the integer. I think you could just cast it.
So just do:
long value = (long)objResult.Properties["pwdLastSet"][0];
DateTime pwdLastSet = DateTime.FromFileTimeUtc(value);