gpt4 book ai didi

c# - 在 C# 中将 LDAP AccountExpires 转换为 DateTime

转载 作者:可可西里 更新时间:2023-11-01 03:12:20 28 4
gpt4 key购买 nike

我想将 18 位字符串从 LDAP AccountExpires 转换为正常日期时间格式。

129508380000000000 >> 2011 年 5 月 26 日

我使用以下链接获得了上述转换。

http://www.chrisnowell.com/information_security_tools/date_converter/Windows_active_directory_date_converter.asp?pwdLastSet,%20accountExpires,%20lastLogonTimestamp,%20lastLogon,%20and%20badPasswordTime

我尝试使用 DateTime.Parse 或 Convert.ToDateTime 进行转换。但没有成功。

有人知道怎么转换吗?非常感谢。

最佳答案

编辑后的答案

根据 Reference,它是自 1601 年 1 月 1 日以来的 UTC 刻度数。 , 描述了 1601 年的意义。很好的背景阅读。

var accountExpires = 129508380000000000;
var dt = new DateTime(1601, 01, 01, 0, 0, 0, DateTimeKind.Utc).AddTicks(accountExpires);

原始接受的答案

这是自 Jan-02-1601 以来的报价数。

DateTime dt = new DateTime(1601, 01, 02).AddTicks(129508380000000000);

关于c# - 在 C# 中将 LDAP AccountExpires 转换为 DateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6360284/

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