首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ActiveDirectoryServices.AccountManagment - LastPasswordSet -协调世界时

ActiveDirectoryServices.AccountManagment - LastPasswordSet -协调世界时
EN

Stack Overflow用户
提问于 2011-04-29 00:30:06
回答 2查看 900关注 0票数 1

我最初使用的是ActiveDirectoryServices,但根据其他成员的建议改用ActiveDirectoryServices.AccountManagment。使用它要容易得多,但它带来了一个挑战。当返回LastPasswordSet时,它使用协调世界时而不是本地时间。我怎么才能避免这个问题呢?

谢谢,

杰森

代码语言:javascript
复制
public UserPrincipal GetUser(string sUserName)
{
    PrincipalContext oPrincipalContext = GetPrincipalContext();

    UserPrincipal oUserPrincipal =
       UserPrincipal.FindByIdentity(oPrincipalContext, sUserName);
    if (oUserPrincipal != null)
    {
        BuildUser(oUserPrincipal);
    }
    return oUserPrincipal;
}

private void BuildUser(UserPrincipal user)
{
    //Populate the user with items available in the UserPrincipal object
    if (user != null)
    {
        if (user.LastPasswordSet.HasValue)
        this.PasswordLastSet = (DateTime)user.LastPasswordSet;
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-04-29 02:52:33

DateTime有一个静态方法SpecifyKind。它指定DateTime对象是表示本地时间、协调世界时,还是未指定为本地时间或协调世界时。Here is the link to original Microsoft documentation

实例方法ToLocalTime将当前DateTime对象的值转换为本地时间。

实例方法ToUniversalTime将当前DateTime对象的值转换为协调世界时。

票数 0
EN

Stack Overflow用户

发布于 2011-04-29 04:59:14

更改

代码语言:javascript
复制
(DateTime)user.LastPasswordSet;

代码语言:javascript
复制
user.LastPasswordSet.Value.ToLocalTime();
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5821927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档