// Convert to a byte array // Note that SQL Server is accurate to 1/300th of a millisecond so we divide by 3.333333 byte[] daysArray = BitConverter.GetBytes(days.Days); byte[] msecsArray = BitConverter.GetBytes((long)(msecs.TotalMilliseconds/3.333333));
// Reverse the bytes to match SQL Servers ordering Array.Reverse(daysArray); Array.Reverse(msecsArray);

// Copy the bytes into the guid Array.Copy(daysArray, daysArray.Length - 2, guidArray, guidArray.Length - 6, 2); Array.Copy(msecsArray, msecsArray.Length - 4, guidArray, guidArray.Length - 4, 4);
return new System.Guid(guidArray); }
//================================================================ /**//// /// 从 SQL SERVER 返回的b2b信息网 GUID 中生成时间信息 /// ///
包含时间信息的IT技术网 COMB /// 时间 public static DateTime GetDateFromComb(System.Guid guid) { DateTime baseDate = new DateTime(1900,1,1); byte[] daysArray = new byte[4]; byte[] msecsArray = new byte[4]; byte[] guidArray = guid.ToByteArray();
// Copy the date parts of the guid to the respective byte arrays. Array.Copy(guidArray, guidArray.Length - 6, daysArray, 2, 2); Array.Copy(guidArray, guidArray.Length - 4, msecsArray, 0, 4);
// Reverse the arrays to put them into the appropriate order Array.Reverse(daysArray); Array.Reverse(msecsArray);
// Convert the bytes to ints int days = BitConverter.ToInt32(daysArray, 0); int msecs = BitConverter.ToInt32(msecsArray, 0);
DateTime date = baseDate.AddDays(days); date = date.AddMilliseconds(msecs * 3.333333);
return date; }
1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.76.77.78.79.80.81.82.83.84.85.86.87.88.89.90.91.92.93.94.95.