久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何將 Active Directory pwdLastSet 轉換為日期/時間

How to convert Active Directory pwdLastSet to Date/Time(如何將 Active Directory pwdLastSet 轉換為日期/時間)
本文介紹了如何將 Active Directory pwdLastSet 轉換為日期/時間的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

    public static string GetProperty(SearchResult searchResult, string PropertyName)
    {
        if (searchResult.Properties.Contains(PropertyName))
        {
            return searchResult.Properties[PropertyName][0].ToString();
        }
        else
        {
            return string.Empty;
        }
    }

上述方法適用于大多數 Active Directory 屬性,但與日期/時間相關的屬性除外,例如 pwdLastSet、maxPwdAge 等.

The above method works great for most Active Directory properties except those that are related to date/time such as pwdLastSet, maxPwdAge, etc.

我的問題是如何將 pwdLastSet 設置為人類可讀的日期時間(例如 8/13/2013 或 2013 年 8 月 13 日等)

My question is how to I get the pwdLastSet to a human readable datetime (like 8/13/2013 or August 13, 2013, etc)

我試過了,但它拋出了異常

I've tries this but it threw exceptions

public static Int64 ConvertADSLargeIntegerToInt64(object adsLargeInteger)
{
    var highPart = (Int32)adsLargeInteger.GetType().InvokeMember("HighPart", System.Reflection.BindingFlags.GetProperty, null, adsLargeInteger, null);
    var lowPart = (Int32)adsLargeInteger.GetType().InvokeMember("LowPart", System.Reflection.BindingFlags.GetProperty, null, adsLargeInteger, null);
    return highPart * ((Int64)UInt32.MaxValue + 1) + lowPart;
}

我使用以下代碼獲取時間為 Int64

I am using the following code to get the time as an Int64

Int64 passwordLastSet = ConvertADSLargeIntegerToInt64(objResult.Properties["pwdLastSet"][0]);

然后我打算使用 DateTime(Int64) 構造函數來創建一個 DateTime

Then I plan on using the DateTime(Int64) constructor to create a DateTime

推薦答案

根據 MSDN 文檔:

此值存儲為一個大整數,表示自 1601 年 1 月 1 日 (UTC) 以來的 100 納秒間隔數.

This value is stored as a large integer that represents the number of 100 nanosecond intervals since January 1, 1601 (UTC).

這與 DateTime.FromFileTimeUtc、如所述完全一致這里.

而且我不確定為什么您覺得需要對整數進行低級操作.我想你可以施展它.

And I'm not sure why you feel the need to do the low level manipulation of the integer. I think you could just cast it.

所以就這樣做:

long value = (long)objResult.Properties["pwdLastSet"][0];
DateTime pwdLastSet = DateTime.FromFileTimeUtc(value);

這篇關于如何將 Active Directory pwdLastSet 轉換為日期/時間的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應該總是在 C# 中使用可空類型)
C# HasValue vs !=null(C# HasValue vs !=null)
C# ADO.NET: nulls and DbNull -- is there more efficient syntax?(C# ADO.NET:空值和 DbNull —— 有沒有更高效的語法?)
How to set null value to int in c#?(如何在c#中將空值設置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調用)
主站蜘蛛池模板: 亚洲狠狠丁香婷婷综合久久久 | 精品国产免费一区二区三区五区 | 草草视频在线播放 | 天天爱爱网 | 亚洲 中文 欧美 日韩 在线观看 | 国产精品毛片 | 成人精品国产 | 黄片毛片 | 99精品视频免费观看 | 国产一区不卡在线观看 | 韩国久久精品 | 免费av手机在线观看 | 男女网站视频 | 91亚洲精选| 欧美成人a∨高清免费观看 色999日韩 | 国产大片黄色 | 午夜影院在线观看视频 | 久久精品国产一区二区电影 | 成人超碰 | 日韩欧美第一页 | 久久久久久免费观看 | 国产一区二区三区高清 | 毛片a级毛片免费播放100 | 丁香综合 | 久久久做| 亚洲精品片 | 中文字幕 亚洲一区 | 国产乱肥老妇国产一区二 | 中文字幕在线一区 | a级免费视频 | 国产a区 | 欧美日韩不卡合集视频 | 国产视频一区二区三区四区五区 | 九九热精品在线 | 亚洲精品乱码 | 精品视频免费 | 欧美日韩中| 天堂网中文字幕在线观看 | 国产一区二区精品 | 国产第一页在线观看 | 国产精品视频播放 |