public class StrToByte {
/**
* 将yyMMddhhmmss格式日期字符串转换成byte[] <br/>
* 其中yy取最大为62即2000--2062
*
* @author linfenliang
* @date 2012-6-19
* @version V1.0.0
* @param dateStr
* :日期字符串
* @return byte[]
*/
public static byte[] strToByte(String dateStr) {
byte[] timeByte = new byte[4];
int[] tempTime = new int[6];
tempTime[0] = Integer.parseInt(dateStr.substring(0, 2));// year
tempTime[1] = Integer.parseInt(dateStr.substring(2, 4));// month
tempTime[2] = Integer.parseInt(dateStr.substring(4, 6));// day
tempTime[3] = Integer.parseInt(dateStr.substring(6, 8));// hh
tempTime[4] = Integer.parseInt(dateStr.substring(8, 10));// mm
tempTime[5] = Integer.parseInt(dateStr.substring(10, 12));// ss
timeByte[0] = (byte) ((tempTime[0] << 2) + (tempTime[1] >> 2));
timeByte[1] = (byte) (((tempTime[1] & 3) << 6) + (tempTime[2] << 1) + (tempTime[3] >> 4 & 1));
timeByte[2] = (byte) (((tempTime[3] & 15) << 4) + ((tempTime[4] >> 2) & 15));
timeByte[3] = (byte) (((tempTime[4] & 3) << 6) + tempTime[5]);
return timeByte;
}

/**
* 将byte数组转换成16进制字符串
*
* @author linfenliang
* @date 2012-6-19
* @version V1.0.0
* @param b:byte[]
* @return String
*/
public static String byteToHexStr(byte[] b) {
StringBuffer sBuffer = new StringBuffer();
for (byte bb : b) {
sBuffer.append(Integer.toHexString(bb & 0xff));
}
return sBuffer.toString();
}

/**
*
* @author linfenliang
* @date 2012-6-19
* @version V1.0.0
* @param args
* void
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
byte[] b = strToByte("120509104354");
System.out.println(byteToHexStr(b));
}

}