/* * Copyright 2019-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package admin.util; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateTime; import lombok.extern.slf4j.Slf4j; import java.sql.Timestamp; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.*; import java.time.format.DateTimeFormatter; import java.util.*; /** * @date: 2020/6/11 16:28 * @apiNote: JDK 8 新日期类 格式化与字符串转换 工具类 */ @Slf4j public class DateUtil { public static final DateTimeFormatter DFY_MD_HMS = DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN); public static final DateTimeFormatter DFY_MD = DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN); public static final String rfcFormatter="yyyy-MM-dd'T'HH:mm:ssXXX"; public static final String FULL_TIME_PATTERN = "yyyyMMddHHmmss"; public static final String FULL_TIME_SPLIT_PATTERN = "yyyy-MM-dd HH:mm:ss"; public static final String CST_TIME_PATTERN = "EEE MMM dd HH:mm:ss zzz yyyy"; public static String formatFullTime(LocalDateTime localDateTime) { return formatFullTime(localDateTime, FULL_TIME_PATTERN); } public static String formatFullTime(LocalDateTime localDateTime, String pattern) { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern); return localDateTime.format(dateTimeFormatter); } /** * LocalDateTime 转时间戳 * * @param localDateTime / * @return / */ public static Long getTimeStamp(LocalDateTime localDateTime) { return localDateTime.atZone(ZoneId.systemDefault()).toEpochSecond(); } public static Timestamp getNowTimestamp(){ return new Timestamp(System.currentTimeMillis()); } /**艾佳地磁奇怪的时间方式转化*/ public static Timestamp parseTimeByTimeString(String yyyyMMddHHmmss){ if(yyyyMMddHHmmss.length()==14) { StringBuilder stringBuilder = new StringBuilder(yyyyMMddHHmmss); return Timestamp.valueOf(stringBuilder.insert(4, "-").insert(7, "-").insert(10, " ").insert(13, ":").insert(16, ":").toString()); } return getNowTimestamp(); } public static boolean isWeekDay(){ int weekday = DateUtil.getWeekOfDate(new Date()); return weekday >= 6; } /** * 是否在时间段内,按起始时间和结束时间按具体时间算 * */ public static boolean isBetweenTimeNow(Timestamp compareTime,Timestamp startTime,Timestamp endTime){ return (startTime).getTime()<=compareTime.getTime()&&(endTime).getTime()>=compareTime.getTime(); } /** String转时间戳 */ public static long dateToMs(String zhDate,String pattern) { SimpleDateFormat format = new SimpleDateFormat(pattern,Locale.getDefault()); try { Date date = format.parse(zhDate); return date.getTime(); } catch (Exception e) { return 0; } } /** * 遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE * 例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。 * @param timestamp * @return */ public static String timestampFormatRfc(Timestamp timestamp) { if(timestamp==null) return ""; DateFormat sdf = new SimpleDateFormat(rfcFormatter); return sdf.format(timestamp); } public static Timestamp getMonthOneDay(Timestamp timestamp) { Calendar calendar1 = Calendar.getInstance(); calendar1.setTimeInMillis(timestamp.getTime()); calendar1.set(calendar1.get(1), calendar1.get(2), 1, 0, 0, 0); Date beginOfDate = calendar1.getTime(); return new Timestamp(calendar1.getTimeInMillis()); } public static Timestamp getYearOneDay(Timestamp timestamp) { Calendar calendar1 = Calendar.getInstance(); calendar1.setTimeInMillis(timestamp.getTime()); calendar1.set(calendar1.get(1), 0, 1, 0, 0, 0); return new Timestamp(calendar1.getTimeInMillis()); } /**加一天*/ public static Timestamp addTimeMonth(Timestamp timestamp, Integer t){ Calendar c = Calendar.getInstance(); c.setTime(timestamp); c.add(Calendar.MONTH, t); // 加一 月 return new Timestamp(c.getTimeInMillis()); } /**加一天*/ public static Timestamp addTimeDay(Timestamp timestamp, Integer t){ Calendar c = Calendar.getInstance(); c.setTime(timestamp); c.add(Calendar.DATE, t); // 加一 天 return new Timestamp(c.getTimeInMillis()); } /**加n分钟*/ public static Timestamp addTimeMinute(Timestamp timestamp, Integer t){ Calendar c = Calendar.getInstance(); c.setTime(timestamp); c.add(Calendar.MINUTE, t); // 加 t 分钟 return new Timestamp(c.getTimeInMillis()); } /** * 是否推送时间,8点后,21点前为推送时间,地磁警告 * */ public static boolean isPushTime8(){ if (DateUtil.getNowTimestamp().compareTo(DateUtil.getNowDayDawnHMS(DateUtil.getNowTimestamp(), 8, 0, 0)) < 0) { return false; } return DateUtil.getNowTimestamp().compareTo(DateUtil.getNowDayDawnHMS(DateUtil.getNowTimestamp(), 21, 0, 0)) <= 0; } /** * 当天起始时间 * */ public static Timestamp getNowDayBeforeDawn(){ Calendar calendar1 = Calendar.getInstance(); calendar1.set(calendar1.get(Calendar.YEAR), calendar1.get(Calendar.MONTH), calendar1.get(Calendar.DAY_OF_MONTH), 0, 0, 0); Date beginOfDate = calendar1.getTime(); return new Timestamp(calendar1.getTimeInMillis()); } /**转化为当天起始时间*/ public static Timestamp convertToNowDayBeforeDawn(Timestamp timestamp){ Calendar calendar1 = Calendar.getInstance(); calendar1.setTimeInMillis(timestamp.getTime()); calendar1.set(calendar1.get(Calendar.YEAR), calendar1.get(Calendar.MONTH), calendar1.get(Calendar.DAY_OF_MONTH), 0, 0, 0); Date beginOfDate = calendar1.getTime(); return new Timestamp(calendar1.getTimeInMillis()); } public static Timestamp getNowDayDawnHMS(Timestamp timestamp, Integer h,Integer m,Integer s){ String t=timestampFormat(timestamp,DatePattern.NORM_DATE_PATTERN)+" "+h+":"+m+":"+s; DateTime dateTime= DateTime.of(t,DatePattern.NORM_DATETIME_PATTERN); return new Timestamp(dateTime.getTime()); } public static Timestamp getNowDayMDHMS(Timestamp timestamp,Integer month,Integer day, Integer h,Integer m,Integer s){ String t=timestampFormat(timestamp,"yyyy")+"-"+month+"-"+day+" "+h+":"+m+":"+s; DateTime dateTime= DateTime.of(t,DatePattern.NORM_DATETIME_PATTERN); return new Timestamp(dateTime.getTime()); } /** * 是否推送时间,7点后,21点前为推送时间 * */ public static boolean isPushTime(){ if (DateUtil.getNowTimestamp().compareTo(DateUtil.getNowDayDawnHMS(DateUtil.getNowTimestamp(), 7, 0, 0)) < 0) { return false; } return DateUtil.getNowTimestamp().compareTo(DateUtil.getNowDayDawnHMS(DateUtil.getNowTimestamp(), 21, 0, 0)) <= 0; } /**加秒数*/ public static Timestamp addTimeSecond(Timestamp timestamp, Integer t){ Calendar c = Calendar.getInstance(); c.setTime(timestamp); c.add(Calendar.SECOND, t); // 加 t 分钟 return new Timestamp(c.getTimeInMillis()); } /** * 结束时间 * */ public static Timestamp getNowDayAfterDawn(){ Calendar calendar1 = Calendar.getInstance(); calendar1.set(calendar1.get(Calendar.YEAR), calendar1.get(Calendar.MONTH), calendar1.get(Calendar.DAY_OF_MONTH), 23, 59, 59); Date beginOfDate = calendar1.getTime(); return new Timestamp(calendar1.getTimeInMillis()); } /**转化为参数时间的最晚时间*/ public static Timestamp convertToNowDayAfterDawn(Timestamp timestamp){ Calendar calendar1 = Calendar.getInstance(); calendar1.setTimeInMillis(timestamp.getTime()); calendar1.set(calendar1.get(Calendar.YEAR), calendar1.get(Calendar.MONTH), calendar1.get(Calendar.DAY_OF_MONTH), 23, 59, 59); Date beginOfDate = calendar1.getTime(); return new Timestamp(calendar1.getTimeInMillis()); } /** * 时间戳转LocalDateTime * * @param timeStamp / * @return / */ public static LocalDateTime fromTimeStamp(Long timeStamp) { return LocalDateTime.ofEpochSecond(timeStamp, 0, OffsetDateTime.now().getOffset()); } /** * LocalDateTime 转 Date * Jdk8 后 不推荐使用 {@link Date} Date * * @param localDateTime / * @return / */ public static Date toDate(LocalDateTime localDateTime) { return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); } /** * LocalDate 转 Date * Jdk8 后 不推荐使用 {@link Date} Date * * @param localDate / * @return / */ public static Date toDate(LocalDate localDate) { return toDate(localDate.atTime(LocalTime.now(ZoneId.systemDefault()))); } /** * Date转 LocalDateTime * Jdk8 后 不推荐使用 {@link Date} Date * * @param date / * @return / */ public static LocalDateTime toLocalDateTime(Date date) { return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); } /** * 日期 格式化 * * @param localDateTime / * @param patten / * @return / */ public static String localDateTimeFormat(LocalDateTime localDateTime, String patten) { DateTimeFormatter df = DateTimeFormatter.ofPattern(patten); return df.format(localDateTime); } /** * 日期 格式化 * * @param timestamp / * @param patten / * @return / */ public static String timestampFormat(Timestamp timestamp, String patten) { if(timestamp==null) return ""; DateFormat sdf = new SimpleDateFormat(patten); return sdf.format(timestamp); } /** * 获取停车时长 * */ public static String getTimeDuration(Timestamp endTime,Timestamp startTime){ if(endTime==null||startTime==null) return ""; long t1 = endTime.getTime(); long t2 = startTime.getTime(); int hours=(int) ((t1 - t2)/(1000*60*60)); int minutes=(int) (((t1 - t2)/1000-hours*(60*60))/60); int second=(int) ((t1 - t2)/1000-hours*(60*60)-minutes*60); return (hours>0?(""+hours+"小时"):"")+(minutes>0?(minutes+"分"):"")+second+"秒"; } /** * 时间相差秒数 * */ public static Integer getTimeSeconds(Timestamp endTime,Timestamp startTime){ if(endTime==null||startTime==null) return 0; long t1 = endTime.getTime(); long t2 = startTime.getTime(); return (int) ((t1 - t2)/1000); } /** * 日期 格式化 * * @param localDateTime / * @param df / * @return / */ public static String localDateTimeFormat(LocalDateTime localDateTime, DateTimeFormatter df) { return df.format(localDateTime); } /** * 日期格式化 yyyy-MM-dd HH:mm:ss * * @param localDateTime / * @return / */ public static String localDateTimeFormatyMdHms(LocalDateTime localDateTime) { return DFY_MD_HMS.format(localDateTime); } public static List getAreaTimeDay(Timestamp bTime, int day) { List timestamps = new ArrayList(); bTime = bTime == null ? getNowTimestamp() : bTime; Timestamp eTime = addTimeDay(bTime, day); if (day > 0) { timestamps.add(bTime); timestamps.add(eTime); } else { timestamps.add(eTime); timestamps.add(bTime); } return timestamps; } public static boolean isBetweenJumpAreaAfterOneMin(long second) { long s = second % 3600L; return s >= 60L && s < 120L; } /** * 日期格式化 yyyy-MM-dd * * @param localDateTime / * @return / */ public String localDateTimeFormatyMd(LocalDateTime localDateTime) { return DFY_MD.format(localDateTime); } /** * 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd * * @param localDateTime / * @return / */ public static LocalDateTime parseLocalDateTimeFormat(String localDateTime, String pattern) { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern); return LocalDateTime.from(dateTimeFormatter.parse(localDateTime)); } /** * 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd * * @param localDateTime / * @return / */ public static LocalDateTime parseLocalDateTimeFormat(String localDateTime, DateTimeFormatter dateTimeFormatter) { return LocalDateTime.from(dateTimeFormatter.parse(localDateTime)); } /** * 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd HH:mm:ss * * @param localDateTime / * @return / */ public static LocalDateTime parseLocalDateTimeFormatyMdHms(String localDateTime) { return LocalDateTime.from(DFY_MD_HMS.parse(localDateTime)); } public static int getWeekOfDate(Date dt) { Calendar cal = Calendar.getInstance(); cal.setTime(dt); int w = cal.get(Calendar.DAY_OF_WEEK) - 1; return w == 0 ? 7 : w; } /** * 两个时间戳是否是同一天 * @param millis1 * @param millis2 * @return */ public static boolean isSameDay(long millis1, long millis2){ long interval = millis1 - millis2; return interval < 86400000 && interval > -86400000 && millis2Days(millis1, TimeZone.getDefault()) == millis2Days(millis2, TimeZone.getDefault()); } private static long millis2Days(long millis, TimeZone timeZone) { return (((long) timeZone.getOffset(millis)) + millis) / 86400000; } /** * 相差分钟数 * @param endTime * @param startTime * @return */ public static Integer getDifferMinute(Timestamp endTime,Timestamp startTime) { Integer parkTimeSeconds = DateUtil.getTimeSeconds(endTime,startTime); return parkTimeSeconds / 60; } /** * 获取计费小时,分开算比较清晰 * */ public static Map getMoneyHour(Timestamp entTime,Timestamp startTime){ Map map=new HashMap<>(); //跨越的整天数 map.put("days",(int) ((getFreeTime(entTime,7,0).getTime() - getFreeTime(startTime,7,0).getTime()) / (1000 * 60 * 60 * 24))); //第一天:晚9点到起始点,负数取0,最后一天从早7点到结束点,负数取0 int bTime=compareTimeMin(getFreeTime(startTime,21,0),startTime); //起始时间在8点40至9点间,不计费 if(isBetweenTimeReal(startTime,DateUtil.getNowDayDawnHMS(startTime,20,40,0),DateUtil.getNowDayDawnHMS(startTime,21,0,0))) bTime=0; int eTime=compareTimeMin(entTime,getFreeTime(entTime,7,0)); if(isBetweenTimeReal(entTime,DateUtil.getNowDayDawnHMS(entTime,7,0,0),DateUtil.getNowDayDawnHMS(entTime,7,20,0))) eTime=0; map.put("bMin",Math.max(bTime,0)); map.put("eMin",Math.max(eTime,0)); return map; } /** * 获取免费时间段 * */ public static Timestamp getFreeTime(Timestamp time,Integer hour,Integer min){ return getNowDayDawnHMS(time, hour, min, 0); } /** * 计算费用时,抛弃7点前,9点后的时候段 时间差分钟数 * */ public static Integer compareTimeMin(Timestamp entTime,Timestamp startTime){ try { //7点前取7点,21点后取21点 if (startTime.compareTo(DateUtil.getNowDayDawnHMS(startTime, 7, 0, 0)) < 0) { startTime = DateUtil.getNowDayDawnHMS(startTime, 7, 0, 0); } if (entTime.compareTo(DateUtil.getNowDayDawnHMS(entTime, 21, 0, 0)) > 0) { entTime = DateUtil.getNowDayDawnHMS(entTime, 21, 0, 0); } long t1 = entTime.getTime(); long t2 = startTime.getTime(); return (int) (((t1 - t2) / 1000) / 60); }catch (Exception ex){ log.error("获取停车耗时compareTimeMin异常,{},{}",entTime,startTime,ex); } return 0; } /** * 是否在时间段内 * */ public static boolean isBetweenTime(Timestamp compareTime,Timestamp startTime,Timestamp endTime){ return (convertToNowDayBeforeDawn(startTime)).getTime()<=compareTime.getTime()&&(convertToNowDayAfterDawn(endTime)).getTime()>=compareTime.getTime(); } public static boolean isBetweenTimeReal(Timestamp compareTime,Timestamp startTime,Timestamp endTime){ return (startTime).getTime()<=compareTime.getTime()&&(endTime).getTime()>=compareTime.getTime(); } /** * 获取某一天的初始时刻 yyyy-MM-dd HH:mm:ss * @param time 任意格式的时间 * @return */ public static String getBeginDayTime(String time){ Date useDate = new Date(); try { useDate = new SimpleDateFormat("yyyy-MM-dd").parse(time); } catch (ParseException e) { e.printStackTrace(); } // 设置查询当天初始时刻 Calendar firstCa = Calendar.getInstance(); firstCa.setTime(useDate); firstCa.set(Calendar.HOUR_OF_DAY, 0); firstCa.set(Calendar.MINUTE, 0); firstCa.set(Calendar.SECOND, 0); firstCa.set(Calendar.MILLISECOND, 1); return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(firstCa.getTime()); } /** * 获取某一天的最后时刻 yyyy-MM-dd HH:mm:ss * @param time 任意格式的时间 * @return */ public static String getEndDayTime(String time){ Date useDate = new Date(); try { useDate = new SimpleDateFormat("yyyy-MM-dd").parse(time); } catch (ParseException e) { e.printStackTrace(); } // 设置查询当天初始时刻 Calendar firstCa = Calendar.getInstance(); firstCa.setTime(useDate); firstCa.set(Calendar.HOUR_OF_DAY, 0); firstCa.set(Calendar.MINUTE, 0); firstCa.set(Calendar.SECOND, 0); firstCa.set(Calendar.MILLISECOND, 1); Calendar lastCa = Calendar.getInstance(); lastCa.setTime(firstCa.getTime()); lastCa.set(Calendar.HOUR_OF_DAY, 0); lastCa.set(Calendar.MINUTE, 0); lastCa.set(Calendar.SECOND, 0); lastCa.set(Calendar.MILLISECOND, 0); lastCa.add(Calendar.DATE, 1); lastCa.add(Calendar.MILLISECOND, -1); return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(lastCa.getTime()); } /** * 获取某个月的初始时刻 yyyy-MM-dd HH:mm:ss * @param time 任意格式的时间 * @return */ public static String getBeginMonthTime(String time){ Date useDate = new Date(); try { useDate = new SimpleDateFormat("yyyy-MM").parse(time); } catch (ParseException e) { e.printStackTrace(); } // 设置查询月第一天初始时刻 Calendar firstCa = Calendar.getInstance(); firstCa.setTime(useDate); firstCa.set(Calendar.DAY_OF_MONTH, 1); firstCa.set(Calendar.HOUR_OF_DAY, 0); firstCa.set(Calendar.MINUTE, 0); firstCa.set(Calendar.SECOND, 0); firstCa.set(Calendar.MILLISECOND, 1); return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(firstCa.getTime()); } /** * 获取某个月的最后时刻 yyyy-MM-dd HH:mm:ss * @param time 任意格式的时间 * @return */ public static String getEndMonthTime(String time){ Date useDate = new Date(); try { useDate = new SimpleDateFormat("yyyy-MM").parse(time); } catch (ParseException e) { e.printStackTrace(); } // 设置查询月第一天初始时刻 Calendar firstCa = Calendar.getInstance(); firstCa.setTime(useDate); firstCa.set(Calendar.DAY_OF_MONTH, 1); firstCa.set(Calendar.HOUR_OF_DAY, 0); firstCa.set(Calendar.MINUTE, 0); firstCa.set(Calendar.SECOND, 0); firstCa.set(Calendar.MILLISECOND, 1); Calendar lastCa = Calendar.getInstance(); lastCa.setTime(firstCa.getTime()); lastCa.set(Calendar.DAY_OF_MONTH, 1); lastCa.set(Calendar.HOUR_OF_DAY, 0); lastCa.set(Calendar.MINUTE, 0); lastCa.set(Calendar.SECOND, 0); lastCa.set(Calendar.MILLISECOND, 0); lastCa.add(Calendar.MONTH, 1); lastCa.add(Calendar.MILLISECOND, -1); return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(lastCa.getTime()); } /** * 获取某年的初始时刻 yyyy-MM-dd HH:mm:ss * @param time 任意格式的时间 * @return */ public static String getBeginYearTime(String time){ Date useDate = new Date(); try { useDate = new SimpleDateFormat("yyyy").parse(time); } catch (ParseException e) { e.printStackTrace(); } //设置查询年第一天 Calendar firstCa = Calendar.getInstance(); firstCa.setTime(useDate); firstCa.set(Calendar.MONTH,0); firstCa.set(Calendar.DAY_OF_MONTH, 1); firstCa.set(Calendar.HOUR_OF_DAY, 0); firstCa.set(Calendar.MINUTE, 0); firstCa.set(Calendar.SECOND, 0); firstCa.set(Calendar.MILLISECOND, 0); return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(firstCa.getTime()); } /** * 获取某年的最后时刻 yyyy-MM-dd HH:mm:ss * @param time 任意格式的时间 * @return */ public static String getEndYearTime(String time){ Date useDate = new Date(); try { useDate = new SimpleDateFormat("yyyy").parse(time); } catch (ParseException e) { e.printStackTrace(); } //设置查询年第一天 Calendar firstCa = Calendar.getInstance(); firstCa.setTime(useDate); firstCa.set(Calendar.MONTH,0); firstCa.set(Calendar.DAY_OF_MONTH, 1); firstCa.set(Calendar.HOUR_OF_DAY, 0); firstCa.set(Calendar.MINUTE, 0); firstCa.set(Calendar.SECOND, 0); firstCa.set(Calendar.MILLISECOND, 0); Calendar lastCa = Calendar.getInstance(); lastCa.setTime(firstCa.getTime()); lastCa.set(Calendar.MONTH,0); lastCa.set(Calendar.DAY_OF_MONTH, 1); lastCa.set(Calendar.HOUR_OF_DAY, 0); lastCa.set(Calendar.MINUTE, 0); lastCa.set(Calendar.SECOND, 0); lastCa.set(Calendar.MILLISECOND, 0); lastCa.add(Calendar.YEAR, 1); lastCa.add(Calendar.MILLISECOND, -1); return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(lastCa.getTime()); } public static String timestampFormatyMdHms(Integer day) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return df.format(addTimeDay(getNowTimestamp(), day)); } public static boolean isBetweenJumpAreaBeforeTenMin(long second) { //20-31分钟之间 if (second >= 1200L && second < 1860L) { return true; } else { long s = second % 3600L; return (s >= 3000L && s <= 3600L) || s<=60; } } public static boolean isBetweenJumpAreaAfterFiveMin(long second) { if (second >= 1800L && second <= 2400L) { return true; } else { long s = second % 3600L; return s >= 0L && s <= 600L; } } public static Timestamp addTimeHour(Timestamp timestamp, Integer t) { Calendar c = Calendar.getInstance(); c.setTime(timestamp); c.add(10, t); return new Timestamp(c.getTimeInMillis()); } public static String getNextQuarterArea(Timestamp now) { int month = now.getMonth() + 1; int lastDay; if (month < 4) { lastDay = addTimeDay(getNowDayMDHMS(now, 7, 1, 0, 0, 0), -1).getDate(); return timestampFormat(getNowDayMDHMS(now, 4, 1, 0, 0, 0), "MM月dd日") + "~" + timestampFormat(getNowDayMDHMS(now, 6, lastDay, 0, 0, 0), "MM月dd日"); } else if (month < 7) { lastDay = addTimeDay(getNowDayMDHMS(now, 10, 1, 0, 0, 0), -1).getDate(); return timestampFormat(getNowDayMDHMS(now, 7, 1, 0, 0, 0), "MM月dd日") + "~" + timestampFormat(getNowDayMDHMS(now, 9, lastDay, 0, 0, 0), "MM月dd日"); } else if (month < 10) { lastDay = addTimeDay(getNowDayMDHMS(now, 1, 1, 0, 0, 0), -1).getDate(); return timestampFormat(getNowDayMDHMS(now, 10, 1, 0, 0, 0), "MM月dd日") + "~" + timestampFormat(getNowDayMDHMS(now, 12, lastDay, 0, 0, 0), "MM月dd日"); } else { lastDay = addTimeDay(getNowDayMDHMS(now, 4, 1, 0, 0, 0), -1).getDate(); return timestampFormat(getNowDayMDHMS(now, 1, 1, 0, 0, 0), "MM月dd日") + "~" + timestampFormat(getNowDayMDHMS(now, 3, lastDay, 0, 0, 0), "MM月dd日"); } } public static Timestamp getNextQuarterDay() { Timestamp now = getNowTimestamp(); int month = now.getMonth(); if (month < 4) { return getNowDayMDHMS(now, 4, 1, 0, 0, 0); } else if (month < 7) { return getNowDayMDHMS(now, 7, 1, 0, 0, 0); } else { return month < 10 ? getNowDayMDHMS(now, 10, 1, 0, 0, 0) : getNowDayMDHMS(now, 1, 1, 0, 0, 0); } } }