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;
Console.WriteLine("Time before set last access time in UTC:");
dt1 = File.GetLastAccessTimeUtc("ABC.TXT");
Console.WriteLine("\tLast Access Time of file(ABC.TXT) in UTC: " + dt1);
File.SetLastAccessTimeUtc("ABC.TXT", DateTime.Now);
Console.WriteLine("Time After set last access time in UTC");
dt1 = File.GetLastAccessTimeUtc("ABC.TXT");
Console.WriteLine("\tLast Access Time of file(ABC.TXT) in UTC: " + dt1);
}
}
}
Output:
Time before set last access time in UTC:
Last Access Time of file(ABC.TXT) in UTC: 10/31/2017 4:25:36 PM
Time After set last access time in UTC
Last Access Time of file(ABC.TXT) in UTC: 10/31/2017 4:37:29 PM
Note: In the above program, we have to recollect, when we use “Record” class, System.IO namespace must be remembered for the program.