请任何人帮助如何将格式为“3676bb6c”的十六进制字符串转换为格式为“1-10-2013 11:47:44”的日期和时间我试过了,但我得到了 12 小时的时间格式,但我需要24小时格式代码如下
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class HexToDate {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//Print.logInfo("REV : " + revHexDate);
//String revHexDate="369E0Ec7";
String revHexDate="F52E32F8";
int decInt = hex2decimal(revHexDate);
System.out.println("11111 "+decInt);
int year = (decInt >> 26);
System.out.println("year is :"+year);
int month = (decInt >> 22) & 0x0f;
System.out.println("month is :"+month);
int date = (decInt >> 17) & 0x1f;
System.out.println("date is :"+date);
int hourOfDay = (decInt >> 12) & 0x1f;
int hrs=decInt/3600;
System.out.println("new hrsis "+hrs);
System.out.println("hourOfDay is :"+hourOfDay);
int minute = (decInt >> 6) & 0x3f;
System.out.println("minute is :"+minute);
int second = (decInt) & 0x3f;
System.out.println("second is :"+second);
Calendar calendar = Calendar.getInstance();
calendar.set(year, month-1, date, hourOfDay, minute, second);
//System.out.println(calendar.getTime());
SimpleDateFormat displayFormat1 = new SimpleDateFormat("ddMMYY",Locale.US);
String DDMMYY = displayFormat1.format(calendar.getTime());
System.out.println("DDMMYY is :"+DDMMYY);
SimpleDateFormat displayFormat2 = new SimpleDateFormat("hhmmss",Locale.US);
String HHMMSS = displayFormat2.format(calendar.getTime());
System.out.println("hhmmss is "+HHMMSS);
}
public static int hex2decimal(String s) {
String digits = "0123456789ABCDEF";
s = s.toUpperCase();
int val = 0;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
int d = digits.indexOf(c);
val = 16*val + d;
}
return val;
}
}