ashish g
ashish g

Reputation: 291

How can I get a file's last modified time in asp.net?

I need to find the time when the file was last modified in a day.

Using the below code I only get the date:

System.IO.File.GetLastWriteTime(Server.MapPath("myFile.txt")).ToString("D");

How to get only the time part?

Upvotes: 3

Views: 7870

Answers (2)

Matthew Shea
Matthew Shea

Reputation: 567

Use HH, mm, ss:

System.IO.File.GetLastWriteTime(Server.MapPath("myFile.txt")).ToString("HH:mm:ss");

Upvotes: 6

Moons
Moons

Reputation: 3854

May be this will help:

 System.IO.File.GetLastWriteTime(@"C:\MyPath\a.txt").TimeOfDay.ToString()

I go this:

17:55:14.3229896

You can format as per your convenience

Upvotes: -1

Related Questions