[Resolved] System.IO.FileInfo - Date Modified
I am trying to get the same date/time as you see in windows explorer for a file and I am using the following code.
Code:
FileInfo myInfo = new FileInfo(listBox1.Items[i].ToString()) ;
myInfo.Refresh();
string dateInfo = myInfo.LastWriteTime.Date.ToLongDateString() + " " + myInfo.LastWriteTime.Date.ToLongTimeString();
The date is correct but the time is always 12:00. Any ideas? Thanks in advance.
Re: System.IO.FileInfo - Date Modified
It is due to the 'Date' when you are converting to a string. However, you don't need to concatenate like that. This should give you what you want.
c# Code:
myInfo.LastWriteTime.ToString("F")
http://msdn2.microsoft.com/en-us/library/az4se3k1.aspx
Re: System.IO.FileInfo - Date Modified
nmadd is quite correct. The MSDN library has all the details of format strings for formatting dates, times and numbers.
http://search.msdn.microsoft.com/sea...=00&lang=en-us
Re: System.IO.FileInfo - Date Modified
Thanks nmadd. Works perfectly.