Export (0) Print
Expand All
Expand Minimize

DateTime.FromBinary Method

Note: This method is new in the .NET Framework version 2.0.

Deserializes a 64-bit binary value and recreates an original serialized DateTime object.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public static DateTime FromBinary (
	long dateData
)
public static DateTime FromBinary (
	long dateData
)
public static function FromBinary (
	dateData : long
) : DateTime

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.

Return Value

A DateTime object that is equivalent to the DateTime object that was serialized by the ToBinary method.

Exception typeCondition

ArgumentException

dateData is less than MinValue or greater than MaxValue.

Use the ToBinary method to convert the value of the current DateTime object to a binary value. Subsequently, use the binary value and the FromBinary method to recreate the original DateTime object.

Local Time Adjustment

A local time, which is a Coordinated Universal Time adjusted to the local time zone, is represented by a DateTime structure whose Kind property has the value Local. If a local DateTime object is serialized in one time zone by the ToBinary method and deserialized in a different time zone by the FromBinary method, the local time represented by the resulting DateTime object is automatically adjusted to the second time zone.

For example, consider a DateTime object that represents a local time of 3 P.M. An application executing in a western time zone uses the ToBinary method to convert that DateTime object to a binary value, then another application executing in a time zone three hours east of the original one uses the FromBinary method to convert the binary value to a new DateTime object. The value of the new DateTime object is 6 P.M., which represents the same point in time as the original 3 P.M. value, but is adjusted to local time in the eastern time zone.

Version Considerations

Starting with the .NET Framework version 2.0, a DateTime structure consists of a private Kind field, which indicates whether the specified time is local time, Coordinated Universal Time (UTC), or neither, concatenated to a private Ticks field, which contains the number of 100-nanosecond ticks that specify a date and time. The number of ticks can be accessed with the Ticks property and theKind field can be accessed with the Kind property.

Prior to the .NET Framework 2.0, if you serialized a DateTime object manually instead of using a serialization interface such as System.Runtime.Serialization.ISerializable, you needed to serialize only the Ticks data in the DateTime. Starting with the .NET Framework 2.0, you must also serialize the Kind data.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft