Generation lapsed time is often used in development, such as membership opening or order lapsed time. You can use the corresponding method according to your needs.

The method also comes with code to calculate X minutes before the current time. It can be obtained by inverse derivation according to the method of sequential calculation.

static GregorianCalendar GC = new GregorianCalendar(); private static final SimpleDateFormat SF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @return */ public static String getXS(int I, int I, int I, int I) Date d) { Calendar calendar = Calendar.getInstance(); calendar.setTime(d); calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + i); return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime()); } public static String getFz(int I, int I, int I, int I, int I, int I) Date d) { Calendar calendar = Calendar.getInstance(); calendar.setTime(d); calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) + i); return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime()); } public static String getFzNitui(int I, int I, int I, int I, int I, int I, int I, int I, int I, int I, int I, int I, Date d) { Calendar calendar = Calendar.getInstance(); calendar.setTime(d); calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) - i); return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime()); } @return */ public static String getDay(int I, Date d) {gc.setTime (d); GC.add(5, +i); GC.set(GC.get(Calendar.YEAR), GC.get(Calendar.MONTH), GC.get(Calendar.DATE)); synchronized (SF) { return SF.format(GC.getTime()); }} public static String getDayNi(int I, int I, int I, int I, int I) Date d) { GC.setTime(d); GC.add(5, -i); GC.set(GC.get(Calendar.YEAR), GC.get(Calendar.MONTH), GC.get(Calendar.DATE)); synchronized (SF) { return SF.format(GC.getTime()); Public static String getWeek(int I, Date d) {gc.setTime (d);}} public static String getWeek(int I, Date d) {gc.setTime (d);  GC.add(3, +i); GC.set(GC.get(Calendar.YEAR), GC.get(Calendar.MONTH), GC.get(Calendar.DATE)); synchronized (SF) { return SF.format(GC.getTime()); }} public static String getMonth(int I, int I, int I, int I, int I, int I, int I) Date d) { GC.setTime(d); GC.add(2, +i); GC.set(GC.get(Calendar.YEAR), GC.get(Calendar.MONTH), GC.get(Calendar.DATE)); synchronized (SF) { return SF.format(GC.getTime()); }} /** * @return */ public static String getMonthNi(int I, Date d) {gc.setTime (d); GC.add(2, -i); GC.set(GC.get(Calendar.YEAR), GC.get(Calendar.MONTH), GC.get(Calendar.DATE)); synchronized (SF) { return SF.format(GC.getTime()); }}Copy the code