Home »
.Net »
C# Programs
C# program to get file creation time
In this C# program, we are going to learn how to print (get) the file creation time? Here, method File.GetCreationTime() is using.
Submitted by IncludeHelp, on October 29, 2017
Here, we have to create a file and print the time, when it is created.
File.GetCreationTime()
This is a method of "File" class, which returns the file creation time.
Syntax:
DateTime GetCreationTime(path);
Parameter(s):
path - Filename with its location.
Return value:
It returns a DateTime object. This contains following information:
- Month
- Date
- Year
- Hour
- Minutes
- Seconds
- AM and PM
Program
using System;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
DateTime D1 = File.GetCreationTime("XYZ.TXT");
Console.WriteLine("File Creation Time : "+D1.ToString());
}
}
}
Output
File Creation Time : 10/27/2017 6:53:39 PM
Note: In above program, we need to remember, when we use "File" class, System.IO namespace must be included in the program.
C# File Handling Programs »