C# program to get last write time in UTC format of file or directory

In this C# program, we will figure out last write time in UTC format of file or directory? To Set last write time in UTC, we are utilizing ‘SetLastWriteTimeUtc()’ technique for ‘Record’ class.

Given a document and an index and we need to Set and print their last write time in UTC design utilizing C# program.

File.SetLastWriteTimeUtc()
This is a strategy for “Record class, which restores the Last Write time of a document or a registry in UTC design.

Syntax:
File.SetLastWriteTimeUtc(path);
Parameter(s):
path – Location of document or catalogue.

Last write time contains the following point of interest:
Date
Month
Year
Hour
Minute
Second
AM/PM

Program

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            DateTime dt1;
            DateTime dt2;

            dt1 = File.GetLastWriteTimeUtc("ABC.TXT");
            Console.WriteLine("Last Write Time in UTC of file(ABC.TXT) : " + dt1);

            dt2 = File.GetLastWriteTimeUtc("mydir");
            Console.WriteLine("Last Write Time in UTC of directory(mydir) : " + dt2);
        }
    }
}

Output

Last Write Time in UTC of file(ABC.TXT) : 10/31/2017 9:38:13 PM
Last Write Time in UTC of directory(mydir) : 10/31/2017 9:08:23 PM

Leave a Comment

error: Alert: Content is protected!!