我正在使用一个没有真正记录的 C++ api 的包装器。一些公开的方法需要 uint 类型的字段(from 和 to)。这些字段实际上是 datefrom 和 dateto,但类型不是这样。我尝试了不同的方法,包括将 datetime 转换为 DOS unsigned int 表示
public ushort ToDosDateTime( DateTime dateTime)
{
uint day = (uint)dateTime.Day; // Between 1 and 31
uint month = (uint)dateTime.Month; // Between 1 and 12
uint years = (uint)(dateTime.Year - 1980); // From 1980
if (years > 127)
throw new ArgumentOutOfRangeException("Cannot represent the year.");
uint dosDateTime = 0;
dosDateTime |= day << (16 - 16);
dosDateTime |= month << (21 - 16);
dosDateTime |= years << (25 - 16);
return unchecked((ushort)dosDateTime);
}
,但如果不是错误,api函数调用仍然没有返回任何内容。,我还尝试了简单的表示形式:20160101,这是有道理的,但没有成功。有没有一种将日期和时间表示为无符号整数的已知方法?