DBase7中的时间戳 [英] Timestamp in DBase7

查看:144
本文介绍了DBase7中的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从.dbf文件读取DBase 7时间戳值。从DBase格式规范中,我得到以下信息:

I'm trying to read DBase 7 timestamp values from .dbf files. From DBase format specification I got the following:


8个字节-两个long,第一个为日期,第二个为时间。该日期是自公元前01/01/4713以来的天数。时间是小时* 3600000L +分钟* 60000L +秒* 1000L

8 bytes - two longs, first for date, second for time. The date is the number of days since 01/01/4713 BC. Time is hours * 3600000L + minutes * 60000L + Seconds * 1000L

但是,我没有通过此算法得到任何正确的值。以下是一些用二进制表示的时间戳值和实际日期时间值:

However, I didn't get any correct values via this algorithm. Here are some timestamp values in binary representation and actual datetime values:

42 CC E1 EC 41 FB 64 00 | 27/08/2013 19:12:13
42 CC E1 ED AF 0E 60 00 | 28/08/2013 08:29:44
42 CC E1 ED B4 DA C0 00 | 28/08/2013 08:42:24
42 CC E1 ED F6 40 F0 00 | 28/08/2013 11:05:16
42 CC E1 EE AE 21 34 00 | 28/08/2013 17:46:57
42 CC E1 EE B1 FB 88 00 | 28/08/2013 17:55:22

有人有阅读这种时间戳格式的经验吗?请帮助我将此二进制数据转换为适当的数据时间值。

Does anybody have experience of reading such timestamp format? Please help me to convert this binary data into appropriate datatime values.

推荐答案

如果类型为DBase VII的时间戳(@),则value是一个大尾数双精度浮点数,其中日期部分是自当前日历开始以来的日历天(0001-01-01的值为1),以毫秒表示,时间部分是自午夜以来的毫秒。 / p>

If the type is DBase VII's timestamp (@) then the value is a big endian double precision floating point where the date part is the calendar days since the start of the current calendar (0001-01-01 has the value of 1) expressed in milliseconds and the time part is the milliseconds since midnight.

function TimestampToUnixMilliseconds(milliseconds) {
    var millisecondsPerDay = 1000 * 60 * 60 * 24,
    millisecondsBetween0001_01_01And1970_01_01 = 719164 * millisecondsPerDay,
    date = Math.trunc(milliseconds / millisecondsBetween0001_01_01And1970_01_01);
    return date
    - millisecondsBetween0001_01_01And1970_01_01
    + millisecondsPerDay
    + Math.round(milliseconds - date);
}

请注意,DBase VII的整数(I),双精度(O)和自动增量(+)类型也使用big endian。整数和双精度数使用最左边的字节作为符号位,其中0表示负数。 FoxPro的二进制类型(B)实际上是DBase VII的double(O),因此您必须检查其8字节的宽度并像这样解析它,而不是在备忘录中进行搜索。

Be aware that the DBase VII's integer (I), double (O) and autoincrement (+) types also use big endian. The integer and double use the leftmost byte as a sign bit where 0 means negative. And the FoxPro's binary type (B) is actually DBase VII's double (O) so you have to check for its 8 byte width and parse it like such, instead of searching in the memo.

这篇关于DBase7中的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆