一、前言
关于LogBack中logback-core源码包中ch.qos.logback.core.util.TimeUtil时间日期工具类,对通过java.util.Calendar、java.util.Date获取当前时间下一秒、下一分钟、下一小时、明天、下一周、下个月具体方法源码示例。
二、源码说明
package ch.qos.logback.core.util;@b@@b@import java.util.Calendar;@b@import java.util.Date;@b@@b@public class TimeUtil {@b@@b@ public static long computeStartOfNextSecond(long now) {@b@ Calendar cal = Calendar.getInstance();@b@ cal.setTime(new Date(now));@b@ cal.set(Calendar.MILLISECOND, 0);@b@ cal.add(Calendar.SECOND, 1);@b@ return cal.getTime().getTime();@b@ }@b@@b@ public static long computeStartOfNextMinute(long now) {@b@ Calendar cal = Calendar.getInstance();@b@ cal.setTime(new Date(now));@b@ cal.set(Calendar.MILLISECOND, 0);@b@ cal.set(Calendar.SECOND, 0);@b@ cal.add(Calendar.MINUTE, 1);@b@ return cal.getTime().getTime();@b@ }@b@@b@ public static long computeStartOfNextHour(long now) {@b@ Calendar cal = Calendar.getInstance();@b@ cal.setTime(new Date(now));@b@ cal.set(Calendar.MILLISECOND, 0);@b@ cal.set(Calendar.SECOND, 0);@b@ cal.set(Calendar.MINUTE, 0);@b@ cal.add(Calendar.HOUR, 1);@b@ return cal.getTime().getTime();@b@ }@b@@b@ public static long computeStartOfNextDay(long now) {@b@ Calendar cal = Calendar.getInstance();@b@ cal.setTime(new Date(now));@b@@b@ cal.add(Calendar.DAY_OF_MONTH, 1);@b@ cal.set(Calendar.MILLISECOND, 0);@b@ cal.set(Calendar.SECOND, 0);@b@ cal.set(Calendar.MINUTE, 0);@b@ cal.set(Calendar.HOUR_OF_DAY, 0);@b@ return cal.getTime().getTime();@b@ }@b@@b@ public static long computeStartOfNextWeek(long now) {@b@ Calendar cal = Calendar.getInstance();@b@ cal.setTime(new Date(now));@b@@b@ cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());@b@ cal.set(Calendar.HOUR_OF_DAY, 0);@b@ cal.set(Calendar.MINUTE, 0);@b@ cal.set(Calendar.SECOND, 0);@b@ cal.set(Calendar.MILLISECOND, 0);@b@ cal.add(Calendar.WEEK_OF_YEAR, 1);@b@ return cal.getTime().getTime();@b@ }@b@@b@ public static long computeStartOfNextMonth(long now) {@b@ Calendar cal = Calendar.getInstance();@b@ cal.setTime(new Date(now));@b@@b@ cal.set(Calendar.DATE, 1);@b@ cal.set(Calendar.HOUR_OF_DAY, 0);@b@ cal.set(Calendar.MINUTE, 0);@b@ cal.set(Calendar.SECOND, 0);@b@ cal.set(Calendar.MILLISECOND, 0);@b@ cal.add(Calendar.MONTH, 1);@b@ return cal.getTime().getTime();@b@ }@b@@b@}