[英]Ad accountexpires setting issue
This code in a console program works fine 控制台程序中的此代码可以正常工作
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())}");
output is 输出是
Entered date : 2/2/2019 6:00:00 PM
FromFileTime: 2/2/2019 6:00:00 PM
When i set this time for an AD attribute like this 当我这次为这样的AD属性设置时
directoryEntry.Properties["accountExpires"].Value = Convert.ToString(enteredDate .ToFileTime());
it is writing the time part as 12:00:00 PM instead of 6pm. 它将时间部分写为12:00:00 PM,而不是6pm。 What am I doing wrong ?
我究竟做错了什么 ?
I assume this is a time zone issue and you are in a UTC+6 time zone. 我认为这是一个时区问题,您处于UTC + 6时区。
I don't think you have a problem at all. 我认为您根本没有问题。 The
accountExpires
attribute stores the time as a number that "represents the number of 100-nanosecond intervals since January 1, 1601 (UTC)". accountExpires
属性将时间存储为一个数字,表示“自1601年1月1日(UTC)起100纳秒间隔的数量”。 That's exactly what ToFileTime()
does for you. 这正是
ToFileTime()
为您所做的。 You're doing it right. 您做对了。
But note that it is stored in UTC. 但是请注意,它存储在UTC中。 If you are seeing it as 12:00 PM, that's probably because you are reading it as UTC time.
如果您在下午12:00看到它,那可能是因为您将它读为UTC时间。
6:00 PM your time is 12:00 PM UTC 您的时间下午6:00是UTC的下午12:00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.