Home »
        VB.Net »
        VB.Net Programs
    
    VB.Net program to get the last access time of a specified file or directory in UTC format
    
    
    
    
	    
		    By Nidhi Last Updated : November 15, 2024
	    
    
    
    Getting the last access time of a file/directory (UTC format) in VB.Net
    Here, we will use GetLastAccessTimeUtc() method of the File directory to set the last access time of the specified file or directory in UTC format.
    
    Program/Source Code:
    The source code to get the last access time of a specified file or directory in UTC format is given below. The given program is compiled and executed successfully.
    VB.Net code to get the last access time of a file/directory (UTC format)
'VB.Net program to get the last access time of a 
'specified file in UTC format.
Imports System.IO
Module Module1
    Sub Main()
        Try
            Dim dt1 As DateTime
            Dim dt2 As DateTime
            dt1 = File.GetLastAccessTimeUtc("sample.txt")
            Console.WriteLine("Last Access Time of file(sample.txt) : " & dt1)
            dt2 = File.GetLastAccessTimeUtc("sampledir")
            Console.WriteLine("Last Access Time of directory(sampledir) : " & dt2)
        Catch ex As FileNotFoundException
            Console.WriteLine("File does not exist")
        End Try
    End Sub
End Module
Output
Last Access Time of file(sample.txt) : 09-01-2021 15:43:35
Last Access Time of directory(sampledir) : 09-01-2021 15:31:01
Press any key to continue . . .
    Explanation
    In the above program, we created the module Module1 that contains the Main() function. The Main() function is the entry point for the program.
    Here, we accessed and printed the last access time of "sample.txt" in UTC format and "sampledir" using GetLastAccessTime() method of File class.
    VB.Net File Handling Programs »
    
    
    
    
   
    
  
    Advertisement
    
    
    
  
  
    Advertisement