Timestamp in DBase7

ε祈祈猫儿з 提交于 2020-03-21 20:04:10

问题


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

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.


回答1:


// 1970-01-01 00:00:00 in units
const UTC_TO_JS = 0x42cc418ba99a00;
// 500 units = 1 second
const SEC_TO_JS = 500;

// 42 CC E1 EC 41 FB 64 00 | 27/08/2013 19:12:13
$hexStr = '42CCE1EC41FB6400';
// get rid of the last byte
$unitsHexStr = substr($hexStr, 0, 14);
// convert hex to decimal
$units = hexdec($unitsHexStr);
// get UTC timestamp
$utcTs = ($units - UTC_TO_JS) / SEC_TO_JS;

$dt = DateTime::createFromFormat('U', $utcTs);
echo $dt->format('Y-m-d H:i:s'); //2013-08-27 19:12:13


来源:https://stackoverflow.com/questions/46909351/timestamp-in-dbase7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!