DateTime.ToBinary() Method in C# Last Updated : 07 Feb, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report This method is used to serializes the current DateTime object to a 64-bit binary value that subsequently can be used to recreate the DateTime object. Syntax: public long ToBinary (); Return Value: This method returns a 64-bit signed integer that encodes the Kind and Ticks properties. Below programs illustrate the use of DateTime.ToBinary() Method Example 1: csharp // C# program to demonstrate the // DateTime.ToBinary() // Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { // creating object of DateTime DateTime date = new DateTime(2011, 1, 1, 4, 0, 15); // Serializes the current DateTime // object to a 64-bit binary value // using ToBinary() method; long value = date.ToBinary(); // Display the value Console.WriteLine("64-bit binary value : {0}", value); } } Output: 64-bit binary value : 634294512150000000 Example 2: csharp // C# program to demonstrate the // DateTime.ToBinary() // Method using System; class GFG { // Main Method public static void Main() { // calling check() method check(new DateTime(2010, 1, 3, 4, 0, 15)); check(new DateTime(2010, 1, 5, 4, 0, 15)); } public static void check(DateTime date) { // Serializes the current DateTime // object to a 64-bit binary value // using ToBinary() method; long value = date.ToBinary(); // Display the value Console.WriteLine("64-bit binary value"+ " of {0} is {1}", date, value); } } Output: 64-bit binary value of 01/03/2010 04:00:15 is 633980880150000000 64-bit binary value of 01/05/2010 04:00:15 is 633982608150000000 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tobinary?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article DateTime.ToFileTime() Method in C# R rohitprasad3 Follow Improve Article Tags : C# CSharp-method CSharp DateTime Struct Similar Reads DateTime.ToOADate() Method in C# This method is used to convert the value of this instance to the equivalent OLE Automation date. Syntax: public double ToOADate (); Return Value: This method returns a double-precision floating-point number that contains an OLE Automation date equivalent to the value of this instance. Exception: Ove 2 min read DateTime.ToFileTime() Method in C# This method is used to convert the value of the current DateTime object to a Windows file time. Syntax: public long ToFileTime (); Return Value: This method returns the value of the current DateTime object expressed as a Windows file time. Exception: This method will give ArgumentOutOfRangeException 2 min read DateTime.ToLongDateString() Method in C# This method is used to convert the value of the current DateTime object to its equivalent long date string representation. Syntax: public string ToLongDateString (); Return Value: This method returns a string that contains the long date string representation of the current DateTime object. Below pro 2 min read DateTime.ToLocalTime() Method in C# This method is used to convert the value of the current DateTime object to local time. Syntax: public DateTime ToLocalTime (); Return Value: This method returns an object whose Kind property is Local, and whose value is the local time equivalent to the value of the current DateTime object, or MaxVal 2 min read DateTime.Subtract() Method in C# This method is used to subtract the specified time or duration from this instance. There are 2 methods in the overload list of this method as follows: Subtract(DateTime) Subtract(TimeSpan) DateTime.Subtract(DateTime) This method is used to subtract the specified date and time from this instance. Syn 3 min read DateTime.ToString() Method in C# | Set â 1 This method is used to Converts the value of the current DateTime object to its equivalent string representation. There are total 4 methods in the overload list of this method: ToString(String, IFormatProvider)ToString(String)ToString(IFormatProvider)ToString() Here, we will discuss only first two m 8 min read Like