///
/// 将BYTE数组转换为DATETIME类型
///
///
///
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();
}
}
————————————————
版权声明:本文为CSDN博主「tenors」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/tenors/article/details/3072783
将BYTE数组转换为DATETIME类型
最新推荐文章于 2023-04-14 01:28:04 发布