Convert LDAP AccountExpires to DateTime in C#(在 C# 中将 LDAP AccountExpires 转换为 DateTime)
问题描述
我想将 18 位字符串从 LDAP AccountExpires 转换为普通日期时间格式.
I want to convert 18 digit string from LDAP AccountExpires to Normal Date Time Format.
129508380000000000 >> 2011 年 5 月 26 日
129508380000000000 >> May 26 2011
我通过以下链接获得了上述转换.
I got the above conversion from using the following link.
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 进行转换.但没有成功.
I tried to convert by using DateTime.Parse or Convert.ToDateTime. But no success.
有人知道如何转换吗?非常感谢.
Anyone know how to convert it? Thanks very much.
推荐答案
编辑答案
根据 参考,它是自 1601 年 1 月 1 日 UTC 以来的刻度数,它描述了 1601 年的意义.良好的背景阅读.
Edited answer
It's the number of ticks since Jan-01-1601 in UTC, according to Reference, which describes the significance of the year 1601. Good background reading.
var accountExpires = 129508380000000000;
var dt = new DateTime(1601, 01, 01, 0, 0, 0, DateTimeKind.Utc).AddTicks(accountExpires);
接受的原始答案
这是自 1601 年 1 月 2 日以来的滴答数.
Original Accepted Answer
It's the number of ticks since Jan-02-1601.
DateTime dt = new DateTime(1601, 01, 02).AddTicks(129508380000000000);
这篇关于在 C# 中将 LDAP AccountExpires 转换为 DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C# 中将 LDAP AccountExpires 转换为 DateTime
基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
