×

VB.Net Programs

VB.Net program to set the last write time of a specified file in UTC format

By Nidhi Last Updated : November 16, 2024

Setting the last write time of a file (UTC format) in VB.Net

Here, we will use SetLastWriteTimeUtc() method of the File directory to set the last write time of the specified file in UTC format.

Program/Source Code:

The source code to set the last access time of a specified file in UTC format is given below. The given program is compiled and executed successfully.

VB.Net code to set the last write time of a file (UTC format)

'VB.Net program to set the last write time of a 
'specified file in UTC format.

Imports System.IO

Module Module1
    Sub Main()
        Try
            Dim dt1 As DateTime

            Console.WriteLine("Time before set last write time in UTC format:")
            dt1 = File.GetLastWriteTimeUtc("sample.txt")
            Console.WriteLine("Last Write Time of file(sample.txt) : " & dt1)

            File.SetLastWriteTimeUtc("sample.txt", DateTime.Now)

            Console.WriteLine("Time After set last write time in UTC format:")

            dt1 = File.GetLastWriteTimeUtc("sample.txt")
            Console.WriteLine("Last Write Time of file(sample.txt) : " & dt1)

        Catch ex As FileNotFoundException
            Console.WriteLine("File does not exist")
        End Try
    End Sub
End Module

Output

Time before set last write time in UTC format:
Last Write Time of file(sample.txt) : 09-01-2021 16:20:47
Time After set last write time in UTC format:
Last Write Time of file(sample.txt) : 09-01-2021 16:23:39
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 set the last write time of "sample.txt" file in UTC format using SetLastWriteTimeUtc() method of File class. Then we printed the updated last write time in UTC format on the console screen.

VB.Net File Handling Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.