如何将datetime转换为byte [] [英] How to convert datetime to byte[]

查看:117
本文介绍了如何将datetime转换为byte []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将dateTime对象转换为byte []。

I am trying to convert dateTime object to byte[].

DateTime dt = Convert.ToDateTime(Current_date_time);





我试图将这个值存储在字节数组中作为



I tried to store this value in byte array as

arrProp = BitConverter.GetBytes(d);





但最终得到例外。

如何解决这个问题?



我的尝试:



byte [] arrProp = null;

DateTime dt = Convert.ToDateTime(objDevice.deviceRecord.Current_date_time);

arrProp = BitConverter.GetBytes(dt);



but ended up getting an exception.
How to resolve this isuue ?

What I have tried:

byte[] arrProp = null;
DateTime dt = Convert.ToDateTime(objDevice.deviceRecord.Current_date_time);
arrProp = BitConverter.GetBytes(dt);

推荐答案

如评论所述,



as commented,

arrProp = BitConverter.GetBytes(dt.Ticks);





:-)



逆操作





:-)

[edit] the inverse operation

DateTime myDateTime = DateTime.FromBinary(BitConverter.ToInt64(arrProp, 0))





[/ edit]



[/edit]


这篇关于如何将datetime转换为byte []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆