Here, we used the Format() function to get the date and time formatted based on the style argument.
Return Value :
The Format() function returns the time of the formatted date as a string.
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
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.