package com.yeshi.buwan.util; import java.text.SimpleDateFormat; import java.util.Date; import javax.persistence.Entity; @Entity public class TimeUtil { public static String getMonthDay(long time) { // yyyy-MM-dd HH:mm:ss SimpleDateFormat sdf = new SimpleDateFormat("MM.dd"); String date = sdf.format(new Date(time)); return date; } public static String getHistoryTime(long time) { // yyyy-MM-dd HH:mm:ss SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm"); String date = sdf.format(new Date(time)); return date; } public static String getAllTime(long time) { // yyyy-MM-dd HH:mm:ss SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); String date = sdf.format(new Date(time)); return date; } public static String getAllNoTime(long time) { // yyyy-MM-dd HH:mm:ss SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm"); String date = sdf.format(new Date(time)); return date; } public static String getyyyyMMddHHTime(long time) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH"); String date = sdf.format(new Date(time)); return date; } public static String getyyyyMMdd(long time) { // yyyy-MM-dd HH:mm:ss SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); String date = sdf.format(new Date(time)); return date; } public static String getAnnoncementTime(long time) { // yyyy-MM-dd HH:mm:ss SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日"); String date = sdf.format(new Date(time)); sdf = new SimpleDateFormat("HH:mm"); String hm = sdf.format(new Date(time)); return date + "\n" + hm; } public static String getCommonTime(long time) { // yyyy-MM-dd HH:mm:ss SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String date = sdf.format(new Date(time)); sdf = new SimpleDateFormat("HH:mm"); String hm = sdf.format(new Date(time)); return date + "\n" + hm; } public static String getGernalTime(long time) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String date = sdf.format(new Date(time)); return date; } public static String getGernalTime(long time, String format) { SimpleDateFormat sdf = new SimpleDateFormat(format); String date = sdf.format(new Date(time)); return date; } public static long convertGernalTime(String st, String format) { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat(format); try { date = sdf.parse(st); // LogUtil.i(date.getTime() + ""); return date.getTime(); } catch (Exception e) { e.printStackTrace(); } return 0; } public static String getExchangeAdTime(long time) { // yyyy-MM-dd HH:mm:ss SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm"); String date = sdf.format(new Date(time)); return date; } public static String getCommentTime(long target) { target = target / 1000; final long dayCut = 2592000L; long now = System.currentTimeMillis() / 1000; long c = now - target; if (c < 60) { return "刚刚"; } else if (c < 60 * 60) return c / (60) + "分钟前"; else if (c < 24 * 60 * 60) return c / (60 * 60) + "小时前"; else if (c < dayCut) return c / (24 * 60 * 60) + "天前"; else if (c < 30 * dayCut) return c / (30L * 24 * 60 * 60) + "个月前"; else return c / (12L * 30L * 24 * 60 * 60) + "年前"; } // 将标准日期转为时间戳 public static long convertDateToTemp(String st) { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { date = sdf.parse(st); LogUtil.i(date.getTime() + ""); return date.getTime(); } catch (Exception e) { e.printStackTrace(); } return 0; } // 将标准日期转为时间戳 public static long convertAllTimeToTemp(String st) { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); try { date = sdf.parse(st); LogUtil.i(date.getTime() + ""); return date.getTime(); } catch (Exception e) { e.printStackTrace(); } return 0; } public static long convertDateToTemp1(String st) { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss"); try { date = sdf.parse(st); LogUtil.i(date.getTime() + ""); return date.getTime(); } catch (Exception e) { e.printStackTrace(); } return 0; } public static long convertDateToTemp2(String st) { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { date = sdf.parse(st); LogUtil.i(date.getTime() + ""); return date.getTime(); } catch (Exception e) { e.printStackTrace(); } return 0; } public static boolean isSameDay(String time1, String time2) { if (getGernalTime(Long.parseLong(time1)).equalsIgnoreCase(getGernalTime(Long.parseLong(time2)))) return true; else return false; } }