gpt4 book ai didi

.net - 如何将 Integer8 值转换为 DateTime?

转载 作者:行者123 更新时间:2023-12-01 08:38:13 24 4
gpt4 key购买 nike

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

最佳答案

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

关于.net - 如何将 Integer8 值转换为 DateTime?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7169749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com