Home » .Net » C# file handling 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:

  1. Month
  2. Date
  3. Year
  4. Hour
  5. Minutes
  6. Seconds
  7. 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.





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.