时间转换为时间戳:
/*
* 将时间转换为时间戳
*/
public static String dateToStamp(String s) throws ParseException{
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse(s);
long ts = date.getTime();
res = String.valueOf(ts);
return res;
}
时间戳转换为时间:
/*
* 将时间戳转换为时间
*/
public static String stampToDate(String s){
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long lt = new Long(s);
Date date = new Date(lt);
res = simpleDateFormat.format(date);
return res;
}

本文提供了两种时间转换的方法:一种是将日期格式的时间字符串转换为时间戳;另一种是将时间戳转换回日期格式的时间字符串。这两种方法均使用了Java的SimpleDateFormat类来定义日期格式。
3821

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



