DateTime.FromBinary(Int64) Method is used to deserialize a 64-bit binary value and recreates an original serialized DateTime object.
Syntax: public static DateTime FromBinary (long dateData);
Here, it takes a 64-bit signed integer that encodes the Kind property in a 2-bit field and the Ticks property in a 62-bit field.
Return Value: This method returns an object that is equivalent to the DateTime object that was serialized by the ToBinary() method.
Exception: This method will give ArgumentException if the dateData is less than MinValue or greater than MaxValue.
Below programs illustrate the use of DateTime.FromBinary(Int64) Method:
DateTime before operation: 2010 January 01 DateTime after operation: 2010 January 01
Example 2: For ArgumentOutOfRangeException
The resulting dateData is less than the MinValue Exception Thrown: System.ArgumentException
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.