Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read created last modified time-stamp of a file using C# [duplicate]

Possible Duplicate:
How to get Modified date from file in c#

How do you, Read created / last modified time-stamp of a file, using C#?

like image 414
Abhijeet Avatar asked Sep 18 '12 20:09

Abhijeet


People also ask

What is the last time a file was accessed or modified?

Access timestamp (atime): which indicates the last time a file was accessed. Modified timestamp (mtime): which is the last time a file’s contents were modified. Change timestamp (ctime): which refers to the last time some metadata related to the file was changed.

How do I find the last modified timestamp in Linux?

Modified timestamp (mtime) indicates the last time the contents of a file were modified. For example, if new contents were added, deleted, or replaced in a file, the modified timestamp is changed. To view the modified timestamp, we can simple use the ls command with -l option. Syntax: ls -l [filename]

How to get the creation and modification time of a file?

We will use getctime () and getmtime () function found inside path module in the os library, for getting the creation and modification times of the file. Both the above function return time in seconds since EPOCH (00:00:00 UTC on 1 January 1970) (time is of float datatype).

What is the difference between modified and change timestamp?

Modified timestamp (mtime): which is the last time a file’s contents were modified. Change timestamp (ctime): which refers to the last time some metadata related to the file was changed. In Linux, a timestamp is actually stored as a number of seconds instead of a date and time.


1 Answers

From: http://www.csharp-examples.net/file-creation-modification-time/

// local times
DateTime creationTime = File.GetCreationTime(@"c:\file.txt");
DateTime lastWriteTime = File.GetLastWriteTime(@"c:\file.txt");
DateTime lastAccessTime = File.GetLastAccessTime(@"c:\file.txt");

// UTC times
DateTime creationTimeUtc = File.GetCreationTimeUtc(@"c:\file.txt");
DateTime lastWriteTimeUtc = File.GetLastWriteTimeUtc(@"c:\file.txt");
DateTime lastAccessTimeUtc = File.GetLastAccessTimeUtc(@"c:\file.txt");

// write file last modification time (local / UTC)
Console.WriteLine(lastWriteTime);     // 9/30/2007 2:16:04 PM
Console.WriteLine(lastWriteTimeUtc);  // 9/30/2007 6:16:04 PM
like image 183
Chimera Avatar answered Sep 19 '22 15:09

Chimera