|
|
@ -374,13 +374,6 @@ public class DateUtils { |
|
|
|
return DateUtils.addDateDays(nextMonth, -1); |
|
|
|
} |
|
|
|
|
|
|
|
// public static void main(String[] args) {
|
|
|
|
// //int weekOfYear = getWeekOfYear(new Date());
|
|
|
|
// String format = String.format("%02d", 9);
|
|
|
|
//
|
|
|
|
// System.out.println(666);
|
|
|
|
// }
|
|
|
|
|
|
|
|
/** |
|
|
|
* 获取日期前一天 |
|
|
|
* @author zhaoqifeng |
|
|
@ -825,24 +818,6 @@ public class DateUtils { |
|
|
|
return com.epmet.commons.tools.utils.DateUtils.format(nowDate, com.epmet.commons.tools.utils.DateUtils.DATE_PATTERN_YYYYMM); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 获取当前日期的前一天日期(yyyy-mm-dd) |
|
|
|
**/ |
|
|
|
public static Date yesterDay() { |
|
|
|
Date date = new Date(); |
|
|
|
try { |
|
|
|
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, -24); |
|
|
|
String str = sdf.format(calendar.getTime()); |
|
|
|
date = sdf.parse(str); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return date; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 格式化日期 |
|
|
|
* @param dateStr String 字符型日期 |
|
|
@ -864,9 +839,9 @@ public class DateUtils { |
|
|
|
* @Author sun |
|
|
|
* @Description 获取当前日期几个自然月之前的日期(yyyy-MM-dd HH:mm:ss) |
|
|
|
**/ |
|
|
|
public static String getBeforeMonthDate(int beforMonth){ |
|
|
|
public static String getBeforeMonthDate(int beforeMonth){ |
|
|
|
Calendar c = Calendar.getInstance(); |
|
|
|
c.add(Calendar.MONTH, - beforMonth); |
|
|
|
c.add(Calendar.MONTH, - beforeMonth); |
|
|
|
Date date = c.getTime(); |
|
|
|
return DateUtils.format(date,DateUtils.DATE_TIME_PATTERN); |
|
|
|
} |
|
|
@ -882,63 +857,6 @@ public class DateUtils { |
|
|
|
return DateUtils.format(date,dateType); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取指定日期的 所在周的第一天和和最后一天 |
|
|
|
* @param dataStr |
|
|
|
* @return |
|
|
|
* @throws ParseException |
|
|
|
*/ |
|
|
|
public static String getLastOfWeek(String dataStr) throws ParseException { |
|
|
|
Calendar cal = Calendar.getInstance(); |
|
|
|
if (StringUtils.isNotBlank(dataStr)){ |
|
|
|
cal.setTime(new SimpleDateFormat(DateUtils.DATE_PATTERN_YYYYMMDD).parse(dataStr)); |
|
|
|
} |
|
|
|
|
|
|
|
int d = 0; |
|
|
|
if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { |
|
|
|
d = -6; |
|
|
|
} else { |
|
|
|
d = 2 - cal.get(Calendar.DAY_OF_WEEK); |
|
|
|
} |
|
|
|
cal.add(Calendar.DAY_OF_WEEK, d); |
|
|
|
// 所在周开始日期
|
|
|
|
String data1 = new SimpleDateFormat(DateUtils.DATE_PATTERN_YYYYMMDD).format(cal.getTime()); |
|
|
|
cal.add(Calendar.DAY_OF_WEEK, 6); |
|
|
|
// 所在周结束日期
|
|
|
|
String data2 = new SimpleDateFormat(DateUtils.DATE_PATTERN_YYYYMMDD).format(cal.getTime()); |
|
|
|
return data1 + "-" + data2; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取指定日期的 所在周的第一天和和最后一天 |
|
|
|
* @param dataStr |
|
|
|
* @return |
|
|
|
* @throws ParseException |
|
|
|
*/ |
|
|
|
public static String getFirstOfWeek(String dataStr) throws ParseException { |
|
|
|
Calendar cal = Calendar.getInstance(); |
|
|
|
if (StringUtils.isNotBlank(dataStr)){ |
|
|
|
cal.setTime(new SimpleDateFormat(DateUtils.DATE_PATTERN_YYYYMMDD).parse(dataStr)); |
|
|
|
} |
|
|
|
|
|
|
|
int d = 0; |
|
|
|
if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { |
|
|
|
d = -6; |
|
|
|
} else { |
|
|
|
d = 2 - cal.get(Calendar.DAY_OF_WEEK); |
|
|
|
} |
|
|
|
cal.add(Calendar.DAY_OF_WEEK, d); |
|
|
|
// 所在周开始日期
|
|
|
|
String data1 = new SimpleDateFormat(DateUtils.DATE_PATTERN_YYYYMMDD).format(cal.getTime()); |
|
|
|
cal.add(Calendar.DAY_OF_WEEK, 6); |
|
|
|
// 所在周结束日期
|
|
|
|
String data2 = new SimpleDateFormat(DateUtils.DATE_PATTERN_YYYYMMDD).format(cal.getTime()); |
|
|
|
return data1 + "-" + data2; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 获取本周的第一天 |
|
|
|
* @return String |
|
|
@ -981,10 +899,8 @@ public class DateUtils { |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws ParseException { |
|
|
|
String first = DateUtils.getFirstOfWeek("20210801"); |
|
|
|
System.out.println(first); |
|
|
|
String fLastOfWeek = DateUtils.getLastOfWeek("20210801"); |
|
|
|
System.out.println(fLastOfWeek); |
|
|
|
Date dayOfMonth = DateUtils.getMonthEnd(DateUtils.addDateMonths(new Date(),-1)); |
|
|
|
System.out.println(DateUtils.format(dayOfMonth, DateUtils.DATE_PATTERN_YYYYMMDD)); |
|
|
|
|
|
|
|
System.out.println(DateUtils.getWeekStart("20210801")); |
|
|
|
System.out.println(DateUtils.getWeekEnd("20210801")); |
|
|
|