我想从 SQL Server 中的 datetime 字段中读取数据并将其存储为 int64,因为 datetime 在 SQL Server 中存储为 64 位。我会做类似的事情吗?
DateTime dt = sqlDataReader.GetDateTime(0);
byte[] bt = BitConverter.GetBytes(dt);
// unfortunately, GetBytes() does not take DateTime as an argument
long ldt = (Convert.ToInt64(bt[0]) << 56)
+ (Convert.ToInt64(bt[1]) << 48)
+ (Convert.ToInt64(bt[2]) << 40)
+ (Convert.ToInt64(bt[3]) << 32)
+ (Convert.ToInt64(bt[4]) << 24)
+ (Convert.ToInt64(bt[5]) << 16)
+ (Convert.ToInt64(bt[6]) << 8)
+ (Convert.ToInt64(bt[7]));