public class TimeFormat {
/**
* 将时间戳转换为时间
* @param s
* @return
* @throws Exception
*/
public static String stampToTime(String s) throws Exception{
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long lt = new Long(s); //将时间戳转换为时间
Date date = new Date(lt); //将时间调整为yyyy-MM-dd HH:mm:ss时间样式
String res = simpleDateFormat.format(date);
return res;
}
/**
* 将时间转换为时间戳
* @param time
* @return
* @throws Exception
*/
public static String dateToStamp(String time) throws Exception {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date date = simpleDateFormat.parse(time);
long ts = date.getTime();
return String.valueOf(ts);
}
}