How do I Convert an Integer8 Value to DateTime?
How do a convert an Integer8 type value to a DateTime one? In particular, I'm attempting to get the accountExpires Active Directory User property in a human-readable form. SearchResult.GetDirectoryEntry.Properti开发者_如何学Goes("accountExpires")
returns a value of "9223372036854775807."
From http://www.dotnet247.com/247reference/msgs/19/96138.aspx
An "Integer8" in AD is an object holding two 32 bit properties, called LowPart and HighPArt. Such a property is returned as an generic RCW (__ComObject), what you need to do is unwrap the underlying object or just cast it to a LargInteger COM type. After that you have to combine both properties into a long (64 Bit), if the value represents a date you have to translate the format from FileTime to DateTime.
Following shows how to retrieve "lastLogon" date property. !!! Set a reference to the activeds.tlb, or create an interop library using tlbimp.exe !!!!
// Use a cast ...
li = pcoll["lastLogon"].Value as LargeInteger;
// Or use CreateWrapperOfType
// li = (LargeIntegerClass)Marshal.CreateWrapperOfType(pcoll["lastLogon"].Value,
typeof(LargeIntegerClass));
// Convert to a long
long date = (((long)(li.HighPart) << 32) + (long) li.LowPart);
// convert date from FileTime format to DateTime
string dt = DateTime.FromFileTime(date).ToString();
Use DateTime.FromFileTime.
http://forums.asp.net/t/999913.aspx/1?Reading+AccountExpires+Property
精彩评论