繁体   English   中英

广告帐户过期设置问题

[英]Ad accountexpires setting issue

控制台程序中的此代码可以正常工作

DateTime enteredDate = DateTime.Parse("2/2/2019 1:16:47 PM");
//change the time to 6pm
enteredDate = enteredDate.Date.Add(new TimeSpan(18, 00, 0));
Debug.WriteLine($"Entered date : {enteredDate}");
Debug.WriteLine($"FromFileTime: DateTime.FromFileTime(enteredDate.ToFileTime())}");

输出是

Entered date : 2/2/2019 6:00:00 PM
FromFileTime: 2/2/2019 6:00:00 PM

当我这次为这样的AD属性设置时

directoryEntry.Properties["accountExpires"].Value = Convert.ToString(enteredDate .ToFileTime());

它将时间部分写为12:00:00 PM,而不是6pm。 我究竟做错了什么 ?

我认为这是一个时区问题,您处于UTC + 6时区。

我认为您根本没有问题。 accountExpires属性将时间存储为一个数字,表示“自1601年1月1日(UTC)起100纳秒间隔的数量”。 这正是ToFileTime()为您所做的。 您做对了。

但是请注意,它存储在UTC中。 如果您在下午12:00看到它,那可能是因为您将它读为UTC时间。

您的时间下午6:00是UTC的下午12:00

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM