java|时间戳和date转换

/** * @param s时间戳 * @returndate类型 */ public static Date timeToDate(String s) { long lt = new Long(s); Date date = new Date(lt); return date; }/** date 转时间戳 * @param date * @return */ public static Long getatime(Date date){ return date.getTime(); }/** * @param s 时间戳 * @returndate字符串 */ public static String stampToDateString(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; }public static void main(String[] args) { // String s = "1546071846000"; Date date=new Date(); String toString = date.toString(); System.out.println(toString); long time = date.getTime(); System.out.println(stampToDateString(s)); System.out.println(timeToDate(s)); }

【java|时间戳和date转换】

    推荐阅读