1.日期转时间戳:
public static String convertToTime(String autoNum) {
String res = "";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");
try {
Date date = simpleDateFormat.parse(autoNum);
long time = date.getTime();
res = String.valueOf(time);
} catch (ParseException e) {
e.printStackTrace();
}
return res;
}
}
2.时间戳转日期:
public static String convertToDate(String s){
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");
long lt = new Long(s);
Date date = new Date(lt);
res = simpleDateFormat.format(date);
return res;
}