java DateUtils 常用工具类
/** * 得到当前时间 * * @return */ public static Date now() { return new Date(); } public static Long getNowStr() { return new Date().getTime(); }
/** * 时间格式化 * * @param date * @return */ public static final String simpleFormat(Date date) { if (date != null) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss"); String strDate = df.format(date); return strDate; } return null; }
/** * 得到两个时间的差值 * * @param dBefor * @param dAfter * @return */ public static final long getDateBetween(Date dBefor, Date dAfter) { long lBefor = 0L; long lAfter = 0L; long lRtn = 0L; lBefor = dBefor.getTime(); lAfter = dAfter.getTime(); lRtn = lAfter - lBefor; return lRtn; }
/** * 在时间上面添加几天 * @param date * @return */ public static Date addDay(Date date, int days) { Calendar c = Calendar.getInstance(); c.setTime(date); c.add(6, days); return c.getTime(); }