java 判断一个日期是否在昨天17点之后

//获取到昨天17:00:00的时间Long类型
  private Long getYesterdayLong(){
        Calendar c1 = Calendar.getInstance();
        c1.add(Calendar.DATE,-1);
        c1.set(Calendar.HOUR_OF_DAY,17);
        c1.set(Calendar.MINUTE,0);
        c1.set(Calendar.SECOND,0);
        c1.set(Calendar.MILLISECOND,0);
        //下面两句可以省略
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out("getYesterdayString:"+simpleDateFormat.format(c1.getTime()));
        return c1.getTimeInMillis();
    }

主要就是这一句了:

c1.set(Calendar.MILLISECOND,0);

你可能感兴趣的:(javaEE)