PDA

Click to See Complete Forum and Search --> : [Resolved] System.IO.FileInfo - Date Modified


jordan23
Aug 23rd, 2007, 06:32 AM
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.


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.

nmadd
Aug 23rd, 2007, 12:57 PM
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.

myInfo.LastWriteTime.ToString("F")

http://msdn2.microsoft.com/en-us/library/az4se3k1.aspx

jmcilhinney
Aug 23rd, 2007, 06:54 PM
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/search/Default.aspx?query=format%20strings&brand=msdn&locale=en-au&refinement=00&lang=en-us

jordan23
Aug 24th, 2007, 06:17 AM
Thanks nmadd. Works perfectly.