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

查看:40
本文介绍了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 个字节 - 两个长整数,第一个是日期,第二个是时间.日期是自公元前 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 的时间戳 (@) 则值是大端双精度浮点数,其中日期部分是自开始日期以来的日历天数当前日历(0001-01-01 的值为 1)以毫秒表示,时间部分是自午夜以来的毫秒数.

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) 和自动增量 (+) 类型也使用大端序.integer 和 double 使用最左边的字节作为符号位,其中 0 表示负数.而 FoxPro 的二进制类型 (B) 实际上是 DBase VII 的双精度 (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天全站免登陆