Home »
VB.Net »
VB.Net Programs
VB.Net program to print date and time in 'dd/mm/yyyy hh:mm:ss' format using Format() function
By Nidhi Last Updated : November 16, 2024
Format() function in VB.Net
Here, we used the Format() function, which is used to get formatted date and time based on style argument.
Syntax
Format(Date, StyleArg)
Parameter(s)
- Date: Given the date object.
- StyleArg: String Argument, which is used to specify the date format.
Return Value
The Format() function will return formatted date time in the form of a string.
VB.Net code to print date and time in 'dd/mm/yyyy hh:mm:ss' format using Format() function
The source code to print date and time in 'dd/mm/yyyy hh:mm:ss' format using Format() function is given below. The given program is compiled and executed successfully.
'VB.Net program to print date and time in
'"dd/mm/yyyy hh:mm:ss" format using Format() function.
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
Press any key to continue . . .
Explanation:
In the above program, we created a module Module1 that contains a Main() method. In the Main() method, we created two variables strDate and D. Here, we assigned the current date and time into the "D" object of Date class using Date.Now.
strDate = Format(D, "General Date")
In the above code, we used function Format(), here we passed date object "D" and style argument "General Date" that will return date in "dd/mm/yyyy hh:mm:ss" format after we printed the formatted date and time on the console screen.
VB.Net Basic Programs »