Read paradox timestamp field

时间:2018-09-19 08:29:11

标签: c++

I am reading a paradox file with the .DB extension. I have successfully read header and records but I have some problem on the Timestamp type. Timestamp take 8 bytes and are formatted like this:

Float field where the integer portion is the number of days since Jan 1, 0001 and the fractional part is the time -- expressed as a proportion of the day. For example, 6:00 PM would be .75 since it is 3/4 of the day past midnight.

I have already read Date type (number of days since Jan 1, 0001). And I know the two following :

1 10000101100 1100111100010110100010001100111000010010101010000000  > 14/11/2017 09:05:18
1 10000101100 1100111010011000001111011111111100101100000000000000  > 21/09/2015 15:01:39

I have the following code:

#include <math.h>
#include <cmath>
union Converter { uint64_t i; double d; };

std::bitset<64> timestamp(0);
double intpart, fractpart;

for (int i = 0; i<end-start; i++) {
    timestamp <<= 8;
    timestamp ^= (unsigned char)(buffer[start+i]);
}
fractpart = modf(convert(timestamp.to_ullong()),&intpart);
unsigned long int test = (unsigned long int)intpart;
std::cout<<test;

Which returns 786841003 for the integer portion, and that number is way too big, even divided by 1000.

EDIT:

std::cout<<std::fixed<<'\n'<<convert(timestamp.to_ullong());
std::cout<<std::fixed<<'\n'<<intpart;

-63578530899343.000000
-63578530899343.000000

I don't have any fractional part, I am maybe reading the bytes in a wrong order?

1 个答案:

答案 0 :(得分:0)

阅读方式错误: 时间戳是从1/1/0001起的毫秒数的两倍,因此我将其转换为:

    double tmsDouble = abs(convert(timestamp.to_ullong()));
    long long int tms= (long long int)tmsDouble ;
    std::cout<<'\n'<<((tms/(86400*1000))-719163)*86400;

我得到一个标准的纪元时间。 719163是1970年1月1日至1/1/0001之间的天数。