// 封装 时间转为四字节
DateTime dt = DateTime.Now;
int time = 0;
time |= dt.Second;
time |= dt.Minute << 6;
time |= dt.Hour << 12;
time |= dt.Day << 17;
time |= dt.Month << 22;
time |= dt.Year - 2000 << 26;
var a = BitConverter.GetBytes(time);
// MessageBox.Show("Test"+ BitConverter.GetBytes(time));
//解析 四字节时间
byte[] datetime = new byte[4];
Buffer.BlockCopy(a, 0, datetime, 0, 4);
int s = datetime[0] & 63;
int m = ((datetime[0] & 192) >> 6) + ((datetime[1] & 15) << 2);
int H = ((datetime[1] & 240) >> 4) + ((datetime[2] & 1) << 4);
int d = (datetime[2] & 62) >> 1;
int Mon = ((datetime[2] & 192) >> 6) + ((datetime[3] & 3) << 2);
int year = (datetime[3] & 252) >> 2;
string dt1 = string.Format("{0}-{1}-{2} {3}:{4}:{5}", year, Mon, d, H, m, s);
|