作者:范二小姐儿 | 来源:互联网 | 2023-05-17 07:15
在java中byte的区间是-128---127给出如下数值
-1,-49,-3,-82,-50,-108,-30,64
将它转换成时间
8 个解决方案
晕,上面的数值是怎么来的?你就知道他们一定表示时间?
把你的byte[]数组转换成String
然后再用SimpleDateFormat转换成Date类型
String strDate = new String(arybyte);
SimpleDateFormat dateFormat=new SimpleDateFormat("yyyyMMdd");//类型自己按你的数据定
Date dateResult=dateFormat.format(strDate );
这两天在做.NET,感觉自己都不会写JAVA了,希望没写错
你想怎么转换?是不是把他们放在一起?你可以用;
string aaa = byte1 + "时" + byte2 +"分"+ byte3 +"秒"+;
然后在转换!
byte arr[]={-1,-49,-3,-82,-50,-108,-30,64};
String stra=new String(arr);
try{
int year = Integer.parseInt(stra.substring(0, 4));
int month = Integer.parseInt(stra.substring(4, 6));
int day = Integer.parseInt(stra.substring(6, 8));
Calendar c1=Calendar.getInstance();
c1.set(year,month,day);
}
catch(Exception e)
{
System.out.println("对不起,您的字节数组中的数据无法转成日期格式");
}
好像没给出你具体转换的要求哦!
没有具体的要求就说要转,这样处理行吗?
-1,-49,-3,-82,-50,-108,-30,64
这些数据是delphi存如的,他们在blob字段中被我读取出来,不过由于java的byte范围在-127---128之间所以得到的16进制与delphi存入的不一样,我想知道如何将自己取出的16进制转换成时间格式,我只知道好象是需要将他们转换成double然后才能转换成时间,但是如何转换不得其解希望各位顶力相助