日期:2014-05-20  浏览次数:20732 次

八个字节的数组转换成时间类型?
接收到服务器的数据为:
76 104 47 33 54 109 -29 64
想转换成时间类型,思路大概是装成long,在转成data
Java code

  byte[] b=new byte[8];
        b[0]=76;
        b[1]=104;
        b[2]=47;
        b[3]=33;
        b[4]=54;
        b[5]=109;
        b[6]=(byte) (-29+256);
        b[7]=64;

         
        BigInteger   bi   =   new   BigInteger(b);  
        long   l   =   bi.longValue();
    
     
        Date mydate=new Date(l);
        System.out.println(mydate.toString());
        SimpleDateFormat format =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String etime=format.format(mydate);
        System.out.println(etime);



但是输出结果为:
Thu Jul 07 20:33:48 CST 174470732
174470732-07-07 20:33:48

并且日期和时间都不对,望解答

------解决方案--------------------
那肯定是发错了,或者你收错了!
Java Doc里面写得很清楚:
new Date(long millisecond),这个参数millisecond是从1970-01-01 00:00:00:000开始计时的毫秒数
------解决方案--------------------
刚才没看清楚,以为你的对方也是JAVA呢
如果是C++,那你得去问问对方这8字节的含义了
------解决方案--------------------
c++越界没关系啊