|
|
@@ -7,6 +7,7 @@ import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.*;
|
|
|
+import java.time.temporal.TemporalAdjusters;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
|
|
|
@@ -531,11 +532,61 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
|
|
public static Integer sumDays(String dates) {
|
|
|
Date date = StringToDate(dates, AFTConstants.YYYYMMDDHHMMSS);
|
|
|
Date now=new Date();
|
|
|
-// long sum=now.getTime()-date.getTime();
|
|
|
-// long one =60*60*24*1000;
|
|
|
-// int days= Math.toIntExact(sum / one);
|
|
|
int days=(int)((now.getTime()-date.getTime())/(1000*3600*24));
|
|
|
return days;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取当前时间
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static LocalDate getToDay() {
|
|
|
+ return LocalDate.now();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static LocalDate gettomorrow() {
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ return today.plusDays(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static LocalDate getFirstDayOfThisWeek() {
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ return today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ // 当前日期
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ System.out.println("今天: " + today);
|
|
|
+
|
|
|
+ // 明天
|
|
|
+ LocalDate tomorrow = today.plusDays(1);
|
|
|
+ System.out.println("明天: " + tomorrow);
|
|
|
+
|
|
|
+ // 本周第一天(假设周一为一周开始)
|
|
|
+ LocalDate firstDayOfThisWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
|
|
+ System.out.println("本周第一天: " + firstDayOfThisWeek);
|
|
|
+
|
|
|
+ // 下周第一天
|
|
|
+ LocalDate firstDayOfNextWeek = firstDayOfThisWeek.plusWeeks(1);
|
|
|
+ System.out.println("下周第一天: " + firstDayOfNextWeek);
|
|
|
+
|
|
|
+ // 本月第一天
|
|
|
+ LocalDate firstDayOfThisMonth = today.withDayOfMonth(1);
|
|
|
+ System.out.println("本月第一天: " + firstDayOfThisMonth);
|
|
|
+
|
|
|
+ // 下月第一天
|
|
|
+ LocalDate firstDayOfNextMonth = today.plusMonths(1).withDayOfMonth(1);
|
|
|
+ System.out.println("下月第一天: " + firstDayOfNextMonth);
|
|
|
+
|
|
|
+ // 今年第一天
|
|
|
+ LocalDate firstDayOfThisYear = today.withDayOfYear(1);
|
|
|
+ System.out.println("今年第一天: " + firstDayOfThisYear);
|
|
|
+
|
|
|
+ // 明年第一天
|
|
|
+ LocalDate firstDayOfNextYear = today.plusYears(1).withDayOfYear(1);
|
|
|
+ System.out.println("明年第一天: " + firstDayOfNextYear);
|
|
|
+ }
|
|
|
+
|
|
|
}
|