PC Review


Reply
Thread Tools Rate Thread

Convert DateTime to Byte Array?

 
 
David
Guest
Posts: n/a
 
      23rd Mar 2005
I need to covert DateTime Variables into a byte array but all of the
conversion methods do not appear to handle the DateTime type. Is
there a generic way to convert any property or object into a byte
array?

Thanks

 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      23rd Mar 2005
David <(E-Mail Removed)> wrote:
> I need to covert DateTime Variables into a byte array but all of the
> conversion methods do not appear to handle the DateTime type. Is
> there a generic way to convert any property or object into a byte
> array?


Well, there's serialization - but for a DateTime, the easiest thing
would be to use the Ticks property to convert it to a long, and then
convert that into a byte array.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      23rd Mar 2005
David,

Because that the datetime is a value, that exist as ticks in the format
long, has it not such much sense to place that in a byteArray. Probably you
want a byte array of a ToString converted format. However that is than
depending from the way as you want it in that byte array.

I hope this helps

Cor


 
Reply With Quote
 
David
Guest
Posts: n/a
 
      23rd Mar 2005
I never considered ticks! I tried a string, but when you convert
back, you loose the time portion!

Thanks

On Wed, 23 Mar 2005 06:52:44 -0000, Jon Skeet [C# MVP]
<(E-Mail Removed)> wrote:

>David <(E-Mail Removed)> wrote:
>> I need to covert DateTime Variables into a byte array but all of the
>> conversion methods do not appear to handle the DateTime type. Is
>> there a generic way to convert any property or object into a byte
>> array?

>
>Well, there's serialization - but for a DateTime, the easiest thing
>would be to use the Ticks property to convert it to a long, and then
>convert that into a byte array.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert a DateTime to byte[] Fabio Microsoft C# .NET 5 1st Mar 2006 07:38 PM
Byte Array from DateTime Array Daniel Microsoft Dot NET Framework 4 27th Dec 2005 05:24 PM
How do I convert a ASCII Byte Array, to another Byte Array Russell Mangel Microsoft Dot NET Framework 2 2nd Feb 2005 06:01 PM
How to Convert Binary Coded Hex Byte Array to Byte Charles Law Microsoft VB .NET 25 2nd Jun 2004 02:21 PM
Convert native byte array (pointer) to managed byte[] Dave Microsoft Dot NET 1 13th Aug 2003 05:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:45 AM.