Home » C#

C# | DateTime.ToBinary() Method with Example

DateTime.ToBinary() Method: Here, we are going to learn about the ToBinary() method of DateTime class with example in C#.
Submitted by IncludeHelp, on October 22, 2019

DateTime.ToBinary() Method

DateTime.ToBinary() method is used to serialize the object of the DateTime class into 64-bit binary value.

Syntax:

    long DateTime.ToBinary();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is long, it returns a binary value representing the DateTime object.

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

In the above program, we took the dt1 object of DateTime class and serialize dt1 into 64-bit value using ToBinary() method and holds the result into binVal variable and print it on the console screen.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.