c# datetime._C#| DateTime.ToBinary()方法与示例

c# datetime.

DateTime.ToBinary()方法 (DateTime.ToBinary() Method)

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

DateTime.ToBinary()方法用于将DateTime类的对象序列化为64位二进制值。

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.

此方法的返回类型为long ,它返回一个表示DateTime对象的二进制值。

Example to demonstrate example of DateTime.ToBinary() method

示例,以演示DateTime.ToBinary()方法的示例

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.

在上面的程序中,我们使用DateTime类的dt1对象,并使用ToBinary()方法将dt1序列化为64位值,并将结果保存到binVal变量中,并将其打印在控制台屏幕上。

翻译自: https://www.includehelp.com/dot-net/datetime-tobinary.aspx

c# datetime.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值