时间戳—时间互转 java

mac2022-06-30  56

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); } }

 

转载于:https://www.cnblogs.com/xiaoQ0725/p/10485426.html

最新回复(0)