Java common tool class: time stamp and time are converted to each other, take what you need!

 package com.lcry.util; import java.text. ParseException; import java.text. SimpleDateFormat; import java.util. Date; /** *Time stamp and time conversion tool class * Created on 2018/12/24. * * @author lcry */ public class DateAndStampUtil { /* *Convert time to timestamp */ /** *(int) Time stamp to Date * * @param timestamp * @return */ public static Date stampForDate(Integer timestamp) { return new Date((long) timestamp * 1000); } /** *(long) Time stamp to Date * * @param timestamp * @return */ public static Date longStampForDate(long timestamp) { return new Date(timestamp); } /** *Date to String * * @param date * @return */ public static String dateForString(Date date) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return sdf.format(date); } /** *String to Date * * @param time * @return */ public static Date stringForDate(String time) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = null; try { date = sdf.parse(time); } catch (ParseException e) { e.printStackTrace(); } return date; } /** *Date to timestamp * * @param data * @return */ public static Integer dateForStamp(Date data) { return (int) (data.getTime() / 1000); } /** *(string) Time to timestamp * * @param s * @return * @throws ParseException */ 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; } /** *(string) Time stamp to date * * @param s * @return */ 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; } }