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.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version