2017-08-31 112 views
0

我正在使用不起作用的DirectorySearcher過濾器,很可能是因爲來自Active Directory的accountExpires屬性的錯誤形式。我想使用LDAP查找所有過期的帳戶,但是如何將DateTime.Now轉換爲accountExpires格式?我找到很多關於將accountExpires轉換爲Datetime格式的文件,但是沒有其他辦法。例如,我發現一個例子說:如何將日期時間轉換爲accountExpires AD屬性?

129383640000000000 is equivalent to Sat, 01 Jan 2011 14:00:00 GMT 

我該如何做另一種方式?我知道這是100納秒,從1月1日1601的區間,但不知道如何計算這個

回答

1

你需要將其轉換爲FILETIME,as per the specification:如果

DateTime dt = DateTime.Now.AddDays(30); 
long ftAccountExpires = dt.ToFileTime(); 

在上面的例子中,您將accountExpires設置爲ftAccountExpires的值,該帳戶將從現在起30天后過期

相關問題