123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740 |
- package cn.cslg.pas.common.utils;
- import cn.hutool.core.date.DateUtil;
- import com.example.xiaoshiweixinback.entity.dto.patent.Calculate;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import java.lang.management.ManagementFactory;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.regex.Pattern;
- public class DateUtils {
- public static final String START_TIME = " 00:00:00";
- public static final String END_TIME = " 23:59:59";
- public final static String FORMAT_STRING = "yyyy-MM-dd HH:mm:ss";
- public final static String[] REPLACE_STRING = new String[]{"GMT+0800", "GMT+08:00"};
- public final static String SPLIT_STRING = "(中国标准时间)";
- public static Logger log = LoggerFactory.getLogger(DateUtils.class);
- public static String YYYY = "yyyy";
- public static String YYYY_MM = "yyyy-MM";
- public static String YYYY_MM_DD = "yyyy-MM-dd";
- public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
- public static String YYYYMMDD = "yyyyMMdd";
- public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
- private static String[] parsePatterns = {
- "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
- "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
- "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
- public static String getDateSourceName(Date startTime, Date endTime, Integer offset, Integer index) {
- String ret = null;
- switch (offset) {
- //月份
- case -1:
- ret = DateUtil.format(startTime, "yyyy-MM");
- break;
- //季度
- case -3:
- ret = String.format("%s-Q%s", DateUtil.format(startTime, "yyyy"), (index % 4) + 1);
- break;
- //半年
- case -6:
- ret = String.format("%s-%s", DateUtil.format(startTime, "yyyy"), index % 2 == 0 ? "H1" : "H2");
- break;
- //1年
- case -12:
- ret = DateUtil.format(startTime, "yyyy");
- break;
- //2年,3年,5年
- case -24:
- case -36:
- case -60:
- ret = String.format("%s-%s", DateUtil.format(DateUtil.offsetMonth(endTime, offset / 12 * -1), "yyyy"), DateUtil.format(startTime, "yyyy"));
- break;
- }
- return ret;
- }
- private DateUtils() {
- }
- public static boolean belongCalendar(Date nowTime, Date beginTime, Date endTime) {
- Calendar date = Calendar.getInstance();
- date.setTime(nowTime);
- Calendar begin = Calendar.getInstance();
- begin.setTime(beginTime);
- Calendar end = Calendar.getInstance();
- end.setTime(endTime);
- return date.after(begin) && date.before(end);
- }
- /**
- * 获取现在的时间 yyyy-MM-dd HH:mm:ss
- */
- public static String getNowTime() {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date date = new Date(System.currentTimeMillis());
- return format.format(date);
- }
- /**
- * 获取当前Date型日期
- *
- * @return Date() 当前日期
- */
- public static Date getNowDate() {
- return new Date();
- }
- public static Integer getDateTime() {
- return (int) (new Date().getTime() / 1000);
- }
- // public static Integer getDateTime(String date) {
- // int dateTime = 0;
- // if (date.contains("/")) {
- // dateTime = Math.toIntExact(strToDateTime(date, parsePatterns[4]).getTime() / 1000);
- // } else if (date.contains("-")) {
- // dateTime = Math.toIntExact(strToDateTime(date, YYYY_MM_DD).getTime() / 1000);
- // }
- // return dateTime;
- // }
- public static Date getDateTime(String date) {
- Date dateTime = null;
- if (date.contains("/")) {
- dateTime = strToDateTime(date, parsePatterns[4]);
- } else if (date.contains("-")) {
- dateTime = strToDateTime(date, YYYY_MM_DD);
- } else if (date.contains(".")) {
- dateTime =strToDateTime(date,parsePatterns[8]);
- }
- return dateTime;
- }
- /**
- * @author 陌溪
- * @date 2018年6月14日
- */
- public static String getNowTimeFormat(String format) {
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
- Date date = new Date(System.currentTimeMillis());
- return simpleDateFormat.format(date);
- }
- public static Date str2Date(String dateString) {
- try {
- dateString = dateString.split(Pattern.quote(SPLIT_STRING))[0].replace(REPLACE_STRING[0], REPLACE_STRING[1]);
- SimpleDateFormat sf1 = new SimpleDateFormat("E MMM dd yyyy HH:mm:ss z", Locale.US);
- return sf1.parse(dateString);
- } catch (Exception e) {
- throw new RuntimeException("时间转化格式错误" + "[dateString=" + dateString + "]" + "[FORMAT_STRING=" + FORMAT_STRING + "]");
- }
- }
- public static Date strToDate(String dateString) {
- try {
- SimpleDateFormat sf1;
- if (dateString.contains("-")) {
- sf1 = new SimpleDateFormat("yyyy-MM-dd");
- } else if (dateString.contains("/")) {
- sf1 = new SimpleDateFormat("yyyy/MM/dd");
- } else if (dateString.contains(":")) {
- sf1 = new SimpleDateFormat("yyyy:MM:dd");
- } else if (dateString.contains(".")) {
- sf1 = new SimpleDateFormat("yyyy.MM.dd");
- } else {
- sf1 = new SimpleDateFormat("yyyyMMdd");
- }
- return sf1.parse(dateString);
- } catch (Exception e) {
- throw new RuntimeException("时间转化格式错误" + "[dateString=" + dateString + "]" + "[FORMAT_STRING=" + FORMAT_STRING + "]");
- }
- }
- /**
- * 获取今天开始的时间
- */
- public static String getToDayStartTime() {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
- Date date = new Date(System.currentTimeMillis());
- return format.format(date);
- }
- /**
- * 获取今天结束的时间
- */
- public static String getToDayEndTime() {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
- Date date = new Date(System.currentTimeMillis());
- return format.format(date);
- }
- /**
- * 获取昨天开始的时间
- */
- public static String getYesterdayStartTime() {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
- Date date = new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000L);
- return format.format(date);
- }
- /**
- * 获取昨天结束的时间
- */
- public static String getYesterdayEndTime() {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
- Date date = new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000L);
- return format.format(date);
- }
- /**
- * 获取某天开始的时间
- */
- public static String getOneDayStartTime(String oneDay) {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
- Date date = new Date(oneDay);
- return format.format(oneDay);
- }
- /**
- * 获取某天开始的日期
- */
- public static String getOneDayStartTime(Date oneDay) {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
- return format.format(oneDay);
- }
- /**
- * 获取某天结束的时间
- */
- public static String getOneDayEndTime(String oneDay) {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
- Date date = new Date(oneDay);
- return format.format(date);
- }
- /**
- * 获取某天结束的日期
- */
- public static String getOneDayEndTime(Date oneDay) {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
- return format.format(oneDay);
- }
- /**
- * 获取本周开始的时间
- */
- public static Date getWeekStartTime() {
- //获得本周一0点时间
- Calendar cal = Calendar.getInstance();
- cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
- cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
- return cal.getTime();
- }
- /**
- * 将 String 转换成 Date
- */
- public static Date strToDateTime(String dateTime) {
- Date date = null;
- try {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- date = format.parse(dateTime);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return date;
- }
- /**
- * 将 String 转换成 Date (转换格式可传入)
- */
- public static Date strToDateTime(String dateTime, String fmt) {
- Date date = null;
- try {
- SimpleDateFormat format = new SimpleDateFormat(fmt);
- date = format.parse(dateTime);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return date;
- }
- /**
- * 将 Date 转换成时间戳
- */
- public static Long dateToStamp(String s) throws ParseException {
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date date = simpleDateFormat.parse(s);
- return date.getTime();
- }
- /**
- * 将 Date 转换成 String
- */
- public static String dateTimeToStr(Date dateTime) {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- return format.format(dateTime);
- }
- public static String dateTimeToStr(Date dateTime, String fmt) {
- SimpleDateFormat format = new SimpleDateFormat(fmt);
- return format.format(dateTime);
- }
- /**
- * 获取本周开始的时间的字符串
- */
- public static String getWeekStartTimeStr() {
- //获得本周一0点时间
- Calendar cal = Calendar.getInstance();
- cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
- cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
- return format.format(cal.getTime());
- }
- /**
- * 获取本周结束的时间
- */
- public static Date getWeekEndTime() {
- Calendar cal = Calendar.getInstance();
- cal.setTime(getWeekStartTime());
- cal.add(Calendar.DAY_OF_WEEK, 7);
- return cal.getTime();
- }
- /**
- * 获取本周结束的时间的字符串
- */
- public static String getWeekEndTimeStr() {
- Calendar cal = Calendar.getInstance();
- cal.setTime(getWeekStartTime());
- cal.add(Calendar.DAY_OF_WEEK, 7);
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
- return format.format(cal.getTime());
- }
- /**
- * 获取上周开始的时间的字符串
- */
- public static String getLastWeekStartTimeStr() {
- int weeks = -1;
- int mondayPlus = getMondayPlus();
- GregorianCalendar currentDate = new GregorianCalendar();
- currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks);
- Date monday = currentDate.getTime();
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
- return format.format(monday);
- }
- /**
- * 获取本月开始的时间
- */
- public static Date getMonthStartTime() {
- Calendar cal = Calendar.getInstance();
- cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
- cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
- return cal.getTime();
- }
- /**
- * 获取本月开始的时间的字符串
- */
- public static String getMonthStartTimeStr() {
- Calendar cal = Calendar.getInstance();
- cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
- cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
- return format.format(cal.getTime());
- }
- /**
- * 获取本月结束的时间
- */
- public static Date getMonthEndTime() {
- Calendar cal = Calendar.getInstance();
- cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
- cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
- cal.set(Calendar.HOUR_OF_DAY, 24);
- return cal.getTime();
- }
- /**
- * 获取本月结束的时间的字符串
- */
- public static String getMonthEndTimeStr() {
- Calendar cal = Calendar.getInstance();
- cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
- cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
- cal.set(Calendar.HOUR_OF_DAY, 24);
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
- return format.format(cal.getTime());
- }
- /**
- * 获取当月的 天数
- */
- public static int getCurrentMonthDay() {
- Calendar a = Calendar.getInstance();
- a.set(Calendar.DATE, 1);
- a.roll(Calendar.DATE, -1);
- return a.get(Calendar.DATE);
- }
- /**
- * 得到二个日期间的间隔天数
- */
- public static int getDayByTwoDay(String date1, String date2) {
- SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
- long day;
- try {
- Date date = myFormatter.parse(date1);
- Date myDate = myFormatter.parse(date2);
- day = (date.getTime() - myDate.getTime()) / (24 * 60 * 60 * 1000);
- } catch (Exception e) {
- return 0;
- }
- return (int) day;
- }
- /**
- * 得到两个日期相差的秒数
- */
- public static int getSecondByTwoDay(Date lastDate, Date date) {
- long second;
- try {
- second = (lastDate.getTime() - date.getTime()) / 1000;
- } catch (Exception e) {
- return 0;
- }
- return (int) second;
- }
- /**
- * 判断某个日期属于本周的第几天 (星期一代表第一天)
- */
- public static int getDaysByWeek(String dateTime) throws ParseException {
- Calendar cal = Calendar.getInstance();
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
- Date date = dateFormat.parse(dateTime);
- cal.setTime(date);
- int day = cal.get(Calendar.DAY_OF_WEEK);
- day = day - 1;
- if (day == 0) {
- day = 7;
- }
- return day;
- }
- /**
- * 判断某个日期属于本月的第几天
- */
- public static int getDaysByMonth(String dateTime) throws ParseException {
- Calendar cal = Calendar.getInstance();
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
- Date date = dateFormat.parse(dateTime);
- cal.setTime(date);
- return cal.get(Calendar.DAY_OF_MONTH);
- }
- /**
- * 根据年 月 获取对应的月份 天数
- */
- public static int getDaysByYearMonth(int year, int month) {
- Calendar a = Calendar.getInstance();
- a.set(Calendar.YEAR, year);
- a.set(Calendar.MONTH, month - 1);
- a.set(Calendar.DATE, 1);
- a.roll(Calendar.DATE, -1);
- return a.get(Calendar.DATE);
- }
- /**
- * 获取当前的年
- */
- public static Integer getYears() {
- Calendar calendar = new GregorianCalendar(TimeZone
- .getDefault());
- return calendar.get(Calendar.YEAR);
- }
- /**
- * 获取当前的月
- */
- public static Integer getMonth() {
- Calendar calendar = new GregorianCalendar(TimeZone
- .getDefault());
- return calendar.get(Calendar.MONTH) + 1;
- }
- /**
- * 获取当前天
- */
- public static Integer getDay() {
- Calendar calendar = new GregorianCalendar(TimeZone
- .getDefault());
- return calendar.get(Calendar.DAY_OF_MONTH);
- }
- /**
- * wx支付的过期时间
- */
- public static String getTime(double hour) {
- long time = (long) (System.currentTimeMillis() + hour * 60 * 60 * 1000L);
- Date date = new Date(time);
- SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
- return format.format(date);
- }
- /**
- * 获得当前日期与本周日相差的天数
- */
- private static int getMondayPlus() {
- Calendar cd = Calendar.getInstance();
- // 获得今天是一周的第几天,星期日是第一天,星期二是第二天......
- // 因为按中国礼拜一作为第一天所以这里减1
- int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK) - 1;
- if (dayOfWeek == 1) {
- return 0;
- } else {
- return 1 - dayOfWeek;
- }
- }
- /**
- * 获取几天之后的日期
- *
- * @param date yyyy-MM-dd HH:mm:ss
- * @param day 加减的天数
- */
- public static Date getDate(String date, int day) {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Calendar cal = Calendar.getInstance();
- Date beforeDate;
- try {
- beforeDate = format.parse(date);
- cal.setTime(beforeDate);
- cal.add(Calendar.DAY_OF_MONTH, day);
- return cal.getTime();
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * 获取某个日期 在加上 秒数的时间
- *
- * @param beforeDate yyyy-MM-dd HH:mm:ss
- * @param timeSecond 加减的秒数
- */
- public static String getDateStr(Date beforeDate, Long timeSecond) {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- try {
- // 返回毫秒数 + 添加的毫秒数
- Long time = beforeDate.getTime() + timeSecond * 1000;
- return format.format(time);
- } catch (Exception e) {
- log.error(e.getMessage());
- }
- return "";
- }
- /**
- * 把date转换成字符串
- */
- public static String formatDate(Date date, String code) {
- SimpleDateFormat format = new SimpleDateFormat(code);
- return format.format(date);
- }
- public static String formatDate(Integer timestamp, String code) {
- if (timestamp == null || timestamp == 0) {
- return "";
- }
- return formatDate(new Date(timestamp * 1000L), code);
- }
- /**
- * 获取过去N天内的日期数组
- *
- * @param intervals intervals天内
- * @param formatStr 格式化字符串 yyyy-MM-dd
- * @return 日期数组
- */
- public static ArrayList<String> getDaysByN(int intervals, String formatStr) {
- ArrayList<String> pastDaysList = new ArrayList<>();
- for (int i = intervals - 1; i >= 0; i--) {
- pastDaysList.add(getPastDate(i, formatStr));
- }
- return pastDaysList;
- }
- /**
- * 获取过去第几天的日期
- */
- public static String getPastDate(int past, String formatStr) {
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - past);
- Date today = calendar.getTime();
- SimpleDateFormat format = new SimpleDateFormat(formatStr);
- return format.format(today);
- }
- /**
- * 获取某个时间段内所有日期
- */
- public static List<String> getDayBetweenDates(String begin, String end) {
- Date dBegin = strToDateTime(begin);
- Date dEnd = strToDateTime(end);
- List<String> lDate = new ArrayList<>();
- SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
- lDate.add(sd.format(dBegin));
- Calendar calBegin = Calendar.getInstance();
- // 使用给定的 Date 设置此 Calendar 的时间
- calBegin.setTime(dBegin);
- Calendar calEnd = Calendar.getInstance();
- // 使用给定的 Date 设置此 Calendar 的时间
- calEnd.setTime(dEnd);
- // 测试此日期是否在指定日期之后
- while (dEnd.after(calBegin.getTime())) {
- // 根据日历的规则,为给定的日历字段添加或减去指定的时间量
- calBegin.add(Calendar.DAY_OF_MONTH, 1);
- lDate.add(sd.format(calBegin.getTime()));
- }
- return lDate;
- }
- /**
- * 获取服务器启动时间
- */
- public static Date getServerStartDate() {
- long time = ManagementFactory.getRuntimeMXBean().getStartTime();
- return new Date(time);
- }
- /**
- * 计算两个时间差
- */
- public static String getDatePoor(Date endDate, Date nowDate) {
- long nd = 1000 * 24 * 60 * 60;
- long nh = 1000 * 60 * 60;
- long nm = 1000 * 60;
- // 获得两个时间的毫秒时间差异
- long diff = endDate.getTime() - nowDate.getTime();
- // 计算差多少天
- long day = diff / nd;
- // 计算差多少小时
- long hour = diff % nd / nh;
- // 计算差多少分钟
- long min = diff % nd % nh / nm;
- return day + "天" + hour + "小时" + min + "分钟";
- }
- public static long getTimeDiff(Date date) {
- long NTime = date.getTime();
- long OTime = getNowDate().getTime();
- return (NTime - OTime) / 1000 / 60;
- }
- public static Date setDateHourAndMinute(Date date, int hour, int minute) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
- calendar.set(Calendar.HOUR_OF_DAY, hour);
- calendar.set(Calendar.MINUTE, minute);
- calendar.set(Calendar.SECOND, 0);
- return calendar.getTime();
- }
- /**
- * 根据起止条数计算开始页数、开始页数的开始位置、结束页数、结束页数的结束位置
- *
- * @param startNumber 起始条数
- * @param endNumber 终止条数
- * @return 返回计算结果对象(开始页数、开始页数的开始位置、结束页数、结束页数的结束位置)
- */
- public static Calculate calculateFromStartAndEndNumber(Integer startNumber, Integer endNumber, Integer pageSize) {
- int startPage; //检索开始页数
- int startNum; //检索开始页数的开始专利位置
- int endPage; //检索结束页数
- int endNum; //检索结束页数的结束专利位置
- if (startNumber % pageSize != 0) {
- startPage = startNumber / pageSize;
- startNum = startNumber % pageSize;
- } else {
- startPage = startNumber / pageSize;
- startNum = pageSize;
- }
- if (endNumber % pageSize != 0) {
- endPage = endNumber / pageSize + 1;
- endNum = endNumber % pageSize;
- } else {
- endPage = endNumber / pageSize;
- endNum = pageSize;
- }
- Calculate calculate = new Calculate()
- .setStartPage(startPage)
- .setStartNum(startNum)
- .setEndPage(endPage)
- .setEndNum(endNum);
- return calculate;
- }
- /**
- * 专利之星返回日期格式为字符串 yyyyMMdd,如 "20230713",本方法将其转成10位数字时间戳
- *
- * @param dateStr yyyyMMdd格式字符串日期
- * @return 返回10位数字时间戳
- */
- public static int stringDateToTimeStamp(String dateStr) {
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
- Date date;
- try {
- date = dateFormat.parse(dateStr);
- } catch (ParseException e) {
- //日期格式转换异常
- e.printStackTrace();
- return Integer.parseInt(dateStr);
- }
- long timeStamp = date.getTime() / 1000;
- return (int) timeStamp;
- }
- /**
- * 获取几天之后的日期
- *
- * @param date yyyy-MM-dd HH:mm:ss
- * @param
- */
- public static Date getPlusMonthDate(Date date, int month) {
- Calendar cal = Calendar.getInstance();
- try {
- cal.setTime(date);
- cal.add(Calendar.MONTH, month);
- return cal.getTime();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- public static void main(String[] args) {
- System.out.println(12 % 50);
- }
- }
|