账户锁定时间错了2小时
Account lockout time wrong by 2 hours
获取AD用户锁定账号的时间,我使用如下代码:
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, result.SamAccountName);
string = user.AccountLockoutTime.Value.ToString("yyyy-MM-dd HH:mm");
不过,停工时间好像差了整整两个小时。怎么了?是时区相关,还是AD服务器时间不对?
来自remarks section of the MSDN documentation on the AccountLockoutTime
property:
As with all DateTime properties in System.DirectoryServices.AccountManagement, the time returned is in UTC form. To convert it to local time, call the ToLocalTime method on the return object.
使用
user.AccountLockoutTime.Value.ToLocalTime().ToString("yyyy-MM-dd HH:mm");
获取您当地时区的日期和时间。
获取AD用户锁定账号的时间,我使用如下代码:
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, result.SamAccountName);
string = user.AccountLockoutTime.Value.ToString("yyyy-MM-dd HH:mm");
不过,停工时间好像差了整整两个小时。怎么了?是时区相关,还是AD服务器时间不对?
来自remarks section of the MSDN documentation on the AccountLockoutTime
property:
As with all DateTime properties in System.DirectoryServices.AccountManagement, the time returned is in UTC form. To convert it to local time, call the ToLocalTime method on the return object.
使用
user.AccountLockoutTime.Value.ToLocalTime().ToString("yyyy-MM-dd HH:mm");
获取您当地时区的日期和时间。