Commit bfcd2964 by 向延琳

增加日期方法

1 parent 3fa39d72
...@@ -9,7 +9,9 @@ import org.eclipse.jetty.util.StringUtil; ...@@ -9,7 +9,9 @@ import org.eclipse.jetty.util.StringUtil;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -1495,6 +1497,38 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils { ...@@ -1495,6 +1497,38 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
return dateTime2; return dateTime2;
} }
/**
* 获取一天的最后时刻
* @param dateStr yyyy-MM-dd
* @return yyyy-MM-dd HH:mm:ss
*/
public static String getLastDateTimeForDate(String dateStr) {
LocalDate date = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern(YMD));
LocalDateTime dateTime = LocalDateTime.of(date, LocalTime.MAX);
return dateTime.format(DateTimeFormatter.ofPattern(YMDHMS));
}
/**
* 今日零点
* @return yyyy-MM-dd HH:mm:ss
*/
public static String getTodayFirstDateTimeStr() {
LocalDate date = LocalDate.now();
LocalDateTime dateTime = LocalDateTime.of(date, LocalTime.MIN);
return dateTime.format(DateTimeFormatter.ofPattern(YMDHMS));
}
/**
* 今日 23:59:59
* @return yyyy-MM-dd HH:mm:ss
*/
public static String getTodayLastDateTimeStr() {
LocalDate date = LocalDate.now();
LocalDateTime dateTime = LocalDateTime.of(date, LocalTime.MAX);
return dateTime.format(DateTimeFormatter.ofPattern(YMDHMS));
}
public static void main(String[] args) { public static void main(String[] args) {
// System.out.println(formatDate(getStartDateOfCurrentDay(new Date()))); // System.out.println(formatDate(getStartDateOfCurrentDay(new Date())));
System.out.println(getMaxDayOfCurrentMonth()); System.out.println(getMaxDayOfCurrentMonth());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!