Datetime 未知的时间和日期格式
我正在使用别人编写的代码来加载我找不到任何文档或规范的文件格式。文件格式为*.vpd,这是用于EKG的varioport读卡器的输出 它读取4个字节的时间和4个字节的日期,并分别存储在4个元素的数组中。在我的测试文件中,4个时间字节是{19,38,3,0},4个日期字节是{38,9,8,0}。它也可能是一个32位的int,写这篇文章的人读错了。从两者的尾随0判断,我将假设小endian,在这种情况下,time和date作为int32的值分别是206355和526630 您知道有任何以4字节(或单个int)表示的时间/日期格式吗?我现在完全迷路了 编辑:我应该补充一点,我不知道这些值可能是什么,除了日期可能在过去几年内 代码,没有与之关联的注释Datetime 未知的时间和日期格式,datetime,Datetime,我正在使用别人编写的代码来加载我找不到任何文档或规范的文件格式。文件格式为*.vpd,这是用于EKG的varioport读卡器的输出 它读取4个字节的时间和4个字节的日期,并分别存储在4个元素的数组中。在我的测试文件中,4个时间字节是{19,38,3,0},4个日期字节是{38,9,8,0}。它也可能是一个32位的int,写这篇文章的人读错了。从两者的尾随0判断,我将假设小endian,在这种情况下,time和date作为int32的值分别是206355和526630 您知道有任何以4字节(或单
s.Rstime = fread(fid, 4, 'uint8');
s.Rsdate = fread(fid, 4, 'uint8');
这已经不重要了,我怀疑任何人都无法回答。在Varioport VPD文件格式中,BCD(二进制编码的十进制)代码用于日期和时间。你没有机会猜到这一点,因为你发布的fread电话显然是胡说八道。你在错误的地方读书 在C/C++中尝试此操作(matlab代码看起来非常类似):
你能帮我发一些密码吗?也许代码中的注释会有帮助。除了测试文件之外,你还有其他东西吗?很抱歉,我错过了这个答案!作为BCD,你说得对,我现在得到了合理的时间和日期:)。非常感谢
typedef struct
{
int channelCount;
int scanRate;
unsigned char measureDate[3];
unsigned char measureTime[3];
...
}
VPD_FILEINFO;
...
unsigned char threeBytes[3];
size_t itemsRead = 0;
errno_t err = _tfopen_s(&fp, filename, _T("r+b"));
// n.b.: vpd files have big-endian byte order!
if (err != 0)
{
_tprintf(_T("Cannot open file %s\n"), filename);
return false;
}
// read date of measurement
fseek(fp, 16, SEEK_SET);
itemsRead = fread(&threeBytes, 1, 3, fp);
if (itemsRead != 3)
{
_tprintf(_T("Error trying to read measureDate\n"));
return false;
}
else
{
info.measureDate[0] = threeBytes[0]; // day, binary coded decimal
info.measureDate[1] = threeBytes[1]; // month, binary coded decimal
info.measureDate[2] = threeBytes[2]; // year, binary coded decimal
}
// read time of measurement
fseek(fp, 12, SEEK_SET);
itemsRead = fread(&threeBytes, 1, 3, fp);
if (itemsRead != 3)
{
_tprintf(_T("Error trying to read measureTime\n"));
return false;
}
else
{
info.measureTime[0] = threeBytes[0]; // hours, binary coded decimal
info.measureTime[1] = threeBytes[1]; // minutes, binary coded decimal
info.measureTime[2] = threeBytes[2]; // seconds, binary coded decimal
}
...
_tprintf(_T("Measure date == %x %x %x\n"),
info.measureDate[0],
info.measureDate[1],
info.measureDate[2]);
_tprintf(_T("Measure time == %x %x %x\n"),
info.measureTime[0],
info.measureTime[1],
info.measureTime[2]);