In another question,我问过如何将64位_ComObject转换为本机DateTime。我也希望能够做到相反。
将64位_ComObject转换为DateTime的代码:
<DirectoryProperty("lastLogonTimestamp")>
Public Property LastLogonTimestamp() As Date?
Get
'Dim valueArray = GetProperty("whenChanged")
Dim valueArray = ExtensionGet("lastLogonTimestamp") 'ExtensionGet("LastLogon")
If valueArray Is Nothing OrElse valueArray.Length = 0 Then Return Nothing
Dim lastLogonDate = valueArray(0)
Dim lastLogonDateType = lastLogonDate.GetType()
Dim highPart = CType(lastLogonDateType.InvokeMember("HighPart", Reflection.BindingFlags.GetProperty, Nothing, lastLogonDate, Nothing), Int32)
Dim lowPart = CType(lastLogonDateType.InvokeMember("LowPart", Reflection.BindingFlags.GetProperty Or Reflection.BindingFlags.Public, Nothing, lastLogonDate, Nothing), Int32)
Dim longDate = CLng(highPart) << 32 Or CLng(lowPart)
Dim result = IIf(longDate > 0, CType(DateTime.FromFileTime(longDate), DateTime?), Nothing)
Return result
'Return DateTime.FromFileTimeUtc(valueArray(0))
End Get
Set(value As Date?)
ExtensionSet("lastLogonTimestamp", value)
End Set
End Property
使用示例日期时间值#2/19/2018 8:17:20 AM#,我需要转换为64位代表日期和时间部分。我认为价值应该是131635198405088370,我之所以这么认为是因为当我检查日期时间值时,AD会这么说。
我试过了..
Dim my64bitDate = DateTime.Parse("#2/19/2018 8:17:20 AM#").ToFileTime
...返回131635198400000000,这只是我期望值的一部分。
更新:
根据HansPrassant的输入,我尝试了更精确的日期时间值2/19/2018 8:17:21 0000001 AM(加1秒和1纳秒?),这导致价值131635198410000001所以我相信这是有效的正确的。
答案 0 :(得分:0)
这有效...... Dim my64bitDate = DateTime.Parse("#2/19/2018 8:17:20 AM#").ToFileTime
最初,我一直在使用包含更精确值的Active Directory属性lastLogonTimestamp
中的值。在属性上用作过滤器不需要此精度。这是一件好事,因为它在上述解析过程中丢失了。
如果原始问题和评论不清楚,请在下面的评论中提出问题 - 我会尽力回答。感谢。