C# DateTime.ToBinary() Method with Example

Syntax

 long DateTime.ToBinary();

Example to demonstrate example of DateTime.ToBinary() method

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create object of datetime class
            DateTime dt1 = new DateTime(2019,1,1,5,0,15);

            
            //Serializes the dt1 to 64-bit binary value
            long binVal = dt1.ToBinary();


            //Print the value
            Console.WriteLine("64-bit binary value of dt1 : " + binVal);

            Console.WriteLine();  
        }
    }
}

Output

64-bit binary value of dt1 : 636819156150000000

Leave a Comment

error: Alert: Content is protected!!