【发布时间】:2011-08-24 02:16:54
【问题描述】:
如何将 Integer8 类型值转换为 DateTime 值?特别是,我试图以人类可读的形式获取 accountExpires Active Directory User 属性。 SearchResult.GetDirectoryEntry.Properties("accountExpires") 返回值“9223372036854775807”。
【问题讨论】:
标签: .net active-directory
如何将 Integer8 类型值转换为 DateTime 值?特别是,我试图以人类可读的形式获取 accountExpires Active Directory User 属性。 SearchResult.GetDirectoryEntry.Properties("accountExpires") 返回值“9223372036854775807”。
【问题讨论】:
标签: .net active-directory
来自http://www.dotnet247.com/247reference/msgs/19/96138.aspx
AD 中的“Integer8”是一个拥有两个 32 位属性的对象,称为 低部分和高部分。这样的属性作为通用 RCW 返回 (__ComObject),您需要做的是展开底层对象或 只需将其转换为 LargeInteger COM 类型。之后你必须结合 如果值表示日期,则将两个属性都转换为 long(64 位) 您必须将格式从 FileTime 转换为 DateTime。
以下显示如何检索“lastLogon”日期属性。 !!!设置一个 引用 activeds.tlb,或使用创建互操作库 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();
【讨论】:
使用 DateTime.FromFileTime。
http://forums.asp.net/t/999913.aspx/1?Reading+AccountExpires+Property
【讨论】: