![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
DateTime.ToBinary() Method in C#
The DateTime.ToBinary() method in C# is used to serialize the current DateTime object to a 64-bit binary value that can be used to recreate the DateTime object. The return value is a 64-bit signed integer.
Syntax
Following is the syntax −
public long ToBinary ();
Example
Let us now see an example to implement the DateTime.ToBinary() method −
using System; public class Demo { public static void Main() { DateTime d = new DateTime(2019, 10, 10, 8, 10, 40); Console.WriteLine("Date = {0}", d); long res = d.ToBinary(); Console.WriteLine("64-bit binary value : {0}", res); } }
Output
This will produce the following output −
Date = 10/10/2019 8:10:40 AM 64-bit binary value : 637062918400000000
Example
Let us now see another example to implement the DateTime.ToBinary() method −
using System; public class Demo { public static void Main() { DateTime d = DateTime.Now; Console.WriteLine("Date = {0}", d); long res = d.ToBinary(); Console.WriteLine("64-bit binary value : {0}", res); } }
Output
This will produce the following output −
Date = 10/16/2019 8:15:56 AM 64-bit binary value : -8586303931293472296
Advertisements