In this C# program, we will figure out how to get the last access time of record or index in UTC position? To get last access time in UTC, we are utilizing ‘GetLastAccessTimeUtc()’ technique for ‘Record’ class.
Given a document and an index and we need to get and print their last access time in UTC design utilizing C# program.
File.GetLastAccessTimeUtc()
This is a strategy for “Record class, which restores the last access time of a document or a registry in UTC design.
Syntax:
File.GetLastAccessTimeUtc(path);
Parameter(s):
path – Location of document or catalogue.
Last access 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.GetLastAccessTimeUtc("ABC.TXT");
Console.WriteLine("Last Access Time of file(ABC.TXT) in UTC: " + dt1);
dt2 = File.GetLastAccessTimeUtc("mydir");
Console.WriteLine("Last Access Time of directory(mydir) in UTC : " + dt2);
}
}
}
Output:
Last Access Time of file(ABC.TXT) in UTC: 10/31/2017 4:25:36 PM
Last Access Time of directory(mydir) in UTC : 10/31/2017 3:38:23 PM
Note: In the above program, we have to recollect, when we use “Record” class, System.IO namespace must be remembered for the program.