Home »
VB.Net »
VB.Net Programs
VB.Net program to get the last write time of a specified file or directory in UTC format
Here, we are going to learn how to get the last write time of a specified file or directory in UTC format in VB.Net?
Submitted by Nidhi, on January 11, 2021
Here, we will use GetLastWriteTimeUtc() method of the File directory to set the last write time of the specified file or directory in UTC format.
Program/Source Code:
The source code to get the last write time of a specified file or directory in UTC format is given below. The given program is compiled and executed successfully.
'VB.Net program to get the last write time of a specified file
'or directory in UTC format.
Imports System.IO
Module Module1
Sub Main()
Try
Dim dt1 As DateTime
Dim dt2 As DateTime
dt1 = File.GetLastWriteTimeUtc("sample.txt")
Console.WriteLine("Last Write Time of file(sample.txt) in UTC format : " + dt1)
dt2 = File.GetLastWriteTimeUtc("sampledir")
Console.WriteLine("Last Write Time of directory(sampledir) in UTC format : " + dt2)
Catch ex As FileNotFoundException
Console.WriteLine("File does not exist")
End Try
End Sub
End Module
Output:
Last Write Time of file(sample.txt) in UTC format : 06-01-2021 16:49:23
Last Write Time of directory(sampledir) in UTC format : 09-01-2021 15:30:45
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 get the last write time of "sample.txt" or "sampledir" in UTC format using GetLastWriteTimeUtc() method of File class. Then we printed the write time on the console screen.
TOP Interview Coding Problems/Challenges