java 时间

1.获取当前时间
DateUtil.toSqlDate(DateUtil.getNowDate("yyyy-MM-dd"))
new Timestamp(DateUtil.getSysDateLong())

2.获取当前年月日
  public static String getNowDate() {
    return new SimpleDateFormat("yyyy年MM月dd日").format(new java.util.Date(System.currentTimeMillis()));
  }

3.时间相差天数比较
<%
    Calendar c1 = Calendar.getInstance();
    Calendar c2 = Calendar.getInstance();
    c1.setTime(project.getAuthorizeDate());
    c2.setTime(project.getActualEndDate());
    long l1 = c1.getTimeInMillis();   
    long l2 = c2.getTimeInMillis();   
    // 计算天数   
    long days = (l2 - l1) / (24 * 60 * 60 * 1000);
   
     %>
或者
DateUtil.daysBetween(date1, date2)

你可能感兴趣的:(java)