import java.util.Date;
public class DateUtil {
public static String date2String(String format, Date date) {
return new SimpleDateFormat(format).format(date);
}
public static Date string2Date(String format, String date) {
try {
return new SimpleDateFormat(format).parse(date);
} catch (Exception e) {
return null;
}
}
}
/*
*数字随机生成字符串
*/
public class Random {
public static String getRandomChar() {
int rand = (int) Math.round(Math.random() * 2);
long itmp = 0;
char ctmp = '\u0000';
switch (rand) {
case 1:
itmp = Math.round(Math.random() * 25 + 65);
ctmp = (char) itmp;
return String.valueOf(ctmp);
case 2:
itmp = Math.round(Math.random() * 25 + 97);
ctmp = (char) itmp;
return String.valueOf(ctmp);
default:
itmp = Math.round(Math.random() * 9);
return String.valueOf(itmp);
}
}
public static String getRandomString(int size) {
StringBuffer result = new StringBuffer();
for (int i = 0; i < size; i++) {
result.append(getRandomChar());
}
return result.toString();
}
}