- /// <summary>
- /// 将BYTE数组转换为DATETIME类型
- /// </summary>
- /// <param name="bytes"></param>
- /// <returns></returns>
- private DateTime BytesToDateTime(byte[] bytes)
- {
- if (bytes != null && bytes.Length >= 5)
- {
- int year = 2000 + Convert.ToInt32(BitConverter.ToString(new byte[1] { bytes[0] }, 0));
- int month = Convert.ToInt32(BitConverter.ToString(new byte[1] { bytes[1] }, 0));
- int date = Convert.ToInt32(BitConverter.ToString(new byte[1] { bytes[2] }, 0));
- int hour = Convert.ToInt32(BitConverter.ToString(new byte[1] { bytes[3] }, 0));
- int minute = Convert.ToInt32(BitConverter.ToString(new byte[1] { bytes[4] }, 0));
- DateTime dt = new DateTime(year, month, date, hour, minute, 0);
- return dt;
- }
- else
- {
- return new DateTime();
- }
- }
C#中将Byte数组转化成DateTime类型
最新推荐文章于 2024-05-23 19:05:20 发布