£
£¤£¤£¤
I have got the value of user account's lastlogon time. Its type is Int64.
This value is stored as a large integer that represents the number of 100
nanosecond intervals since January 1, 1601 (UTC)(Refer to MSDN).
I don't know how to convert this value to localTime.
The following is my code.
################################################################
DirectoryEntry deUser = new DirectoryEntry(ldappath);
DirectorySearcher src = new DirectorySearcher(deUser);
src.Filter = "(&(objectClass=user)(SAMAccountName=" +
accountName + "))";
SearchResult result = src.FindOne();
ResultPropertyCollection accountProperties = result.Properties;
foreach (object lastlogon in accountProperties["lastlogon"])
{
//Int64 lastlogon =129046401906875000 ;//this is the value of user
account's lastlogon time.
double aa=Convert.ToDouble(lastlogon.ToString()); // I am not sure that
this is a correct and good method
DateTime dtZone = new DateTime(1601, 1, 1, 0, 0, 0);
dtZone.AddSeconds(aa/10000000);//10^7 ,AddSeconds method needs a double
type parameter.
lbLastLogon.Text = dtZone.ToLocalTime().ToString(); //it displays 1601-1-1
8:0;0,it is
not correct
localtime
}
##################################################################################
I try to use number dirctly as following. Then It returns "2009-12-7
6:16:30" ,Year ,month,day are right ,but the rest is not right.I am in
China.It may need add 8 hours additionally.
**********************************************************
DateTime dtZone = new DateTime(1601, 1, 1, 0, 0, 0);
lbLastLogon .Text =dtZone
..AddSeconds(12904640190687500000/1000000000).ToString ()
**********************************************************
This value is stored as a large integer that represents the number of 100
nanosecond intervals since January 1, 1601 (UTC)(Refer to MSDN).
I don't know how to convert this value to localTime.
The following is my code.
################################################################
DirectoryEntry deUser = new DirectoryEntry(ldappath);
DirectorySearcher src = new DirectorySearcher(deUser);
src.Filter = "(&(objectClass=user)(SAMAccountName=" +
accountName + "))";
SearchResult result = src.FindOne();
ResultPropertyCollection accountProperties = result.Properties;
foreach (object lastlogon in accountProperties["lastlogon"])
{
//Int64 lastlogon =129046401906875000 ;//this is the value of user
account's lastlogon time.
double aa=Convert.ToDouble(lastlogon.ToString()); // I am not sure that
this is a correct and good method
DateTime dtZone = new DateTime(1601, 1, 1, 0, 0, 0);
dtZone.AddSeconds(aa/10000000);//10^7 ,AddSeconds method needs a double
type parameter.
lbLastLogon.Text = dtZone.ToLocalTime().ToString(); //it displays 1601-1-1
8:0;0,it is
not correct
localtime
}
##################################################################################
I try to use number dirctly as following. Then It returns "2009-12-7
6:16:30" ,Year ,month,day are right ,but the rest is not right.I am in
China.It may need add 8 hours additionally.
**********************************************************
DateTime dtZone = new DateTime(1601, 1, 1, 0, 0, 0);
lbLastLogon .Text =dtZone
..AddSeconds(12904640190687500000/1000000000).ToString ()
**********************************************************