代码:
String str = "A";
byte[] bytes = null;
try {
//String -> byte[]
bytes = str.getBytes("utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.println("bytes:"+bytes);
//byte[] -> String
String str2 = null;
try {
str2 = new String(bytes,"utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.println(str2);
代码执行图:
代码图:
Date date = new Date();//当前日期对象
long hm = (date.getTime()-24*3600*1000);//昨日的毫秒数
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("当前时间:"+sdf.format(date));
date.setTime(hm);//设置成昨日的日期对象
System.out.println("昨天时间:"+sdf.format(date));
代码执行图:



