Home >>VB.Net Built-in Functions >VB.Net program to print date and time in 'dd/mm/yyyy hh:mm:ss' format using Format() function

VB.Net program to print date and time in 'dd/mm/yyyy hh:mm:ss' format using Format() function

Write a VB.Net program to print date and time in 'dd/mm/yyyy hh:mm:ss' format using Format() function

Here, we used the Format() function to get the date and time formatted based on the style argument.

Syntax :

Format(Date, StyleArg)

Parameters :

  • Date: Considering the date object.
  • StyleArg: String Argument used to specify the format of the date.

Return Value :

The Format() function returns the time of the formatted date as a string.

Program :

The source code for printing the date and time in the format 'dd/mm/yyyy hh:mm:ss' using Format() is given below. The program given is compiled and successfully executed.


Module Module1
    Sub Main()
        Dim strDate As String
        Dim D As Date
        D = Date.Now
        strDate = Format(D, "General Date")
        Console.WriteLine(strDate)
    End Sub
End Module
	
Output:
11/24/2020 7:14:54 PM

Explanation:

We created a Module1 module in the program above that contains the Main() method. We created two variables, strDate and D, in the Main() method. Here, using Date.Now, we have assigned the current date and time to the D object in the Date class.

strDate = Format(D, "General Date")

In the above code, we used the Format() function, where we passed the date object "D" and the "General Date" style argument, which returns the date in the format "dd/mm/yyyy hh:mm:ss" after we printed the formatted date and time on the console screen.


No Sidebar ads