Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the FromBinary() method of DateTime class
By Nidhi Last Updated : November 11, 2024
DateTime.FromBinary() Method in VB.Net
The FromBinary() method is used to create the object of the DateTime class.
Syntax
Function FromBinary(ByVal bin as Long ) as Date
Parameter(s)
- Bin : Specified long value
Return Value
It returns an object of the DateTime class.
VB.Net code to demonstrate the example of DateTime.FromBinary() method
The source code to demonstrate the FromBinary() method of the DateTime class is given below. The given program is compiled and executed successfully.
'VB.NET program to demonstrate FromBinary() method of
'DateTime class.
Imports System
Module Module1
Sub Main()
Dim date1 As New DateTime(2020, 4, 27, 10, 20, 30)
Dim date2 As New DateTime()
Dim bin As Long = 0
bin = date1.ToBinary()
date2 = DateTime.FromBinary(bin)
Console.WriteLine("Binary value: {0}", bin)
Console.WriteLine("Date: {0}", date2)
End Sub
End Module
Output
Binary value: 637235796300000000
Date: 27-04-2020 10:20:30
Press any key to continue . . .
Explanation
In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program.
In the Main() function, we created an object of the DateTime class and converted the date object into 64-bit binary using ToBinary() method and then get the Date object from 64-bit binary value. After that print the date on the console screen.
VB.Net Date & Time Programs »