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;
}
本文提供了两种实用的方法:一种是将日期字符串转换为时间戳,另一种是将时间戳转换回日期格式。这两种方法使用Java实现,并且适用于常见的日期格式。
3万+

被折叠的 条评论
为什么被折叠?



