I'm creating a C# program that create a packet data. One of the data in the packet is the Date and Time of 4 bytes size. I did this:
public byte[] convertDateTimetoHex4bytes(DateTime dt)
{
//Convert date time format 20091202041800
string str = dt.ToString("yyyyMMddhhmmss");
//Convert to Int32
Int32 decValue = Convert.ToInt32(str);
//convert to bytes
byte[] bytes = BitConverter.GetBytes(decValue);
return bytes;
}
However, it seems that I need to use 8 byte of data, since 32 bit is too small (error during run time). Anyone can help me, if there is any other smaller Date Time format with 4 bytes? or any other way?