C# DateTime FromBinary
Description
DateTime FromBinary
deserializes a 64-bit binary value
and recreates an original serialized DateTime object.
Syntax
DateTime.FromBinary
has the following syntax.
public static DateTime FromBinary(
long dateData
)
Parameters
DateTime.FromBinary
has the following parameters.
dateData
- A 64-bit signed integer that encodes the Kind property in a 2-bit field and the Ticks property in a 62-bit field.
Returns
DateTime.FromBinary
method returns An object that is equivalent to the DateTime object that was serialized by
the ToBinary method.
Example
You can determine whether a particular date and time value may be subject to modification by passing it to the TimeZoneInfo.IsInvalidTime method, as the example illustrates.
/*from ww w .j av a 2s . c o m*/
using System;
public class Example
{
public static void Main()
{
DateTime localDate = new DateTime(2010, 3, 14, 2, 30, 0, DateTimeKind.Local);
long binLocal = localDate.ToBinary();
if (TimeZoneInfo.Local.IsInvalidTime(localDate))
Console.WriteLine("{0} is an invalid time in the {1} zone.",
localDate,
TimeZoneInfo.Local.StandardName);
DateTime localDate2 = DateTime.FromBinary(binLocal);
Console.WriteLine("{0} = {1}: {2}",
localDate, localDate2, localDate.Equals(localDate2));
}
}
The code above generates the following result.