【问题标题】:How do I Convert an Integer8 Value to DateTime?如何将 Integer8 值转换为 DateTime?
【发布时间】:2011-08-24 02:16:54
【问题描述】:

如何将 Integer8 类型值转换为 DateTime 值?特别是,我试图以人类可读的形式获取 accountExpires Active Directory User 属性。 SearchResult.GetDirectoryEntry.Properties("accountExpires") 返回值“9223372036854775807”。

【问题讨论】:

    标签: .net active-directory


    【解决方案1】:

    来自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();
    

    【讨论】:

    • 谢谢,这真的很有帮助!
    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-04
      • 2010-10-30
      • 2021-03-31
      • 1970-01-01
      • 2012-06-20
      • 2013-07-25
      • 2010-09-09
      相关资源
      最近更新 更多