dtddjq9637 2018-10-02 11:30
浏览 92
已采纳

too long

I have this hex 2a ba ce 21 which I have converted to decimal 716885537, now what I have asked to do is:
2a ba ce 21 is given; now print last updated time in seconds (seconds that have elapsed since January 1 Midnight, 2000) - 4 Byte
For converting to standard epoch time, add time offset value 946684800 (time offset from Jan. 1970 to Jan. 2000)

I have searched alot and to be honest every thing got mixed... It would be great help if some one tell me how to do this in PHP.

  • 写回答

1条回答 默认 最新

  • dongxiao9583 2018-10-02 13:33
    关注

    every thing got mixed...

    Trying to unmix the things…
    Presumably your hex bytes are in little-endian order, so you have to reverse before converting.

    <?php
    $timestamp = hexdec(implode(array_reverse(explode(' ', '2a ba ce 21'))));
    echo "seconds:  ", $timestamp+946684800, "
    ";
    echo "readable: ", date('r', $timestamp+946684800), "
    ";
    

    what if i had to convert 2c 00 to last updated time in milliseconds as well that is of 2 byte.

    The conversion goes just like above. If you want to join the milliseconds to the timestamp, add them divided by 1000 to it.

    $timestamp = hexdec(implode(array_reverse(explode(' ', '2a ba ce 21'))));
    $millisecs = hexdec(implode(array_reverse(explode(' ', '2c 00'))));
    $timestamp += 946684800 + $millisecs/1000;
    echo "seconds:  ", $timestamp, "
    ";
    date_default_timezone_set('UTC');
    echo "readable: ", date('Y-m-d H:i:s.', $timestamp).substr("00$millisecs", -3), "
    ";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多