public static TimeSpan ToTimeBCD(byte[] bytes) { if (bytes.Length != 2) { throw new NotSupportedException(); } var origin = ByteConvert.ToUint16(bytes, false); var hh = ByteConvert.FromBCD((byte)((origin & 0xFF00) >> 8)); var mm = ByteConvert.FromBCD((byte)(origin & 0x00FF)); try { return(new TimeSpan(hh, mm, 0)); } catch { } return(TimeSpan.MinValue); }
public static DateTime ToDate(byte[] bytes) { if (bytes.Length != 2) { throw new NotSupportedException(); } var origin = ByteConvert.ToUint16(bytes, false); var YY = (int)(origin & 0xFE00) >> 9; var MM = (int)(origin & 0x01E0) >> 5; var DD = (int)(origin & 0x001F) >> 0; try { return(new DateTime(YY, MM, DD)); } catch { } return(DateTime.MinValue); }