时间转时间戳:
/*
* 将时间转换为时间戳
*/
public static String dateToStamp(String time) throws ParseException{
String stap;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse(time);
long ts = date.getTime();//获取时间的时间戳
stap = String.valueOf(ts);
return stap;
}
时间戳转时间:
/*
* 将时间戳转换为时间
*/
public static String stampToDate(String stap){
String time;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long lt = new Long(stap);
Date date = new Date(lt);
time = simpleDateFormat.format(date);
return time;
}
本文提供了两个实用的方法:一种是将标准日期格式(如yyyy-MM-dd HH:mm:ss)的时间字符串转换为时间戳;另一种则是将时间戳转换回同样的日期格式。这两种方法对于处理日期和时间数据非常有用。
1万+

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



