C# convert LastLogon value to Days

Experts:

This issue has been bothering me for quite some time....

I've got a program I'm designing to assist with local profile removal.  I've got the actual removal of the profile processing correctly, but I'm having problems getting the calculation of the last logon time for the particular profile.

I found the Win32_NetworkLoginProfile class and a LastLogon value that gives the number of seconds past 00:00:00 January 1, 1970 and I need help converting that to a date so I can then find out how long since that last logon occurred.

Any suggestions?
LVL 12
piattndAsked:
Who is Participating?
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Good let me know
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hi, use the TimeSpan.FromSeconds() method
0
 
piattndAuthor Commented:
TimeSpan.FromSeconds(#of seconds returned)?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Carlos VillegasFull Stack .NET DeveloperCommented:
Yes, but I will give you a better code... a moment...
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Clear? :)
string myStringDate = "00:01:15 January 1, 1970";
DateTime myDate = DateTime.Parse(myStringDate);
TimeSpan duration = myDate.Subtract(new DateTime(1970, 1, 1));
Console.WriteLine(duration.TotalSeconds);
Console.WriteLine(duration.TotalMinutes);
Console.WriteLine(duration.TotalHours);
Console.WriteLine(duration.TotalDays);
Console.WriteLine(duration.Days);

Open in new window

0
 
piattndAuthor Commented:
Let me take a look and see if I can figure it out.  I need to look at the value that gets returned from me to let you know what data I have to work with.
0
 
piattndAuthor Commented:
Sorry it took me so long to accept the answer.  Been a crazy few weeks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.