Reputation: 9930
I'm getting info about a user in Active Directory using this code:
SearchResultCollection searchResults = null;
string activeDirFilter = getActiveDirFilter();
DirectoryEntry dirEntry = new DirectoryEntry();
DirectorySearcher searcher = new DirectorySearcher(dirEntry)
{
PageSize = 100,
Filter = activeDirFilter,
SearchScope = SearchScope.Subtree
};
This code works fine and I'm getting these attributes:
LASTLOGON
130388757393977187
PWDLASTSET
130378422326246669
LASTLOGONTIMESTAMP
130380275331980403
However, I can't make sense of the value, does anyone know how to decode those numbers to time stamps?
EDIT: The values can't be seconds since epoch, because 130388757393977187 seconds = 4 131 858.64 millenniums.
It can't be ticks either, because 130388757393977187 = 413 years.
Upvotes: 0
Views: 204
Reputation: 9930
I worked it out:
You need to use
long x = 130388757393977187;
DateTime dateTime = DateTime.FromFileTimeUtc(x);
Upvotes: 1
Reputation: 12196
You currently have the Unix Timestamp
you should convert it into DateTime object and print it.
public static DateTime UnixTimeStampToDateTime(double unixTimeStamp)
{
// Unix timestamp is seconds past epoch
System.DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0,System.DateTimeKind.Utc);
dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
return dtDateTime;
}
Upvotes: 1