Java,Calendar 获得明天凌晨的时间time

/**
 * 获得明天凌晨的时间time
 *
 * @return
 */
private long getNextDayZeroTime()
{
   Calendar calendar = Calendar.getInstance();
   calendar.add(Calendar.DAY_OF_MONTH, 1);
   calendar.set(Calendar.HOUR_OF_DAY, 0);
   calendar.set(Calendar.MINUTE, 0);
   calendar.set(Calendar.SECOND, 0);
   calendar.set(Calendar.MILLISECOND, 0);

   return calendar.getTimeInMillis();
}

/**
 * 根据给定的time获得昨天凌晨的时间
 * 1、time=null,默认系统时间的昨天凌晨时间
 * 2、time!=null,获得给定time的所在天的前一天的凌晨时间
 *
 * @return 昨天凌晨的时间
 */
private static long getYesterdayZeroTimeByTime(Long time) {
    Calendar calendar = Calendar.getInstance();
    if (time != null) {
        calendar.setTimeInMillis(time);
    }
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    return calendar.getTimeInMillis();
}

 

posted @ 2015-10-29 11:05  园芳宝贝  阅读(5428)  评论(0编辑  收藏  举报