|
@@ -1,41 +1,82 @@
|
|
|
package cn.com.ctop.job.bytedance.data.utils;
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
+@Slf4j
|
|
|
public class DateUtils {
|
|
|
|
|
|
- public static Integer getDateInteger(String date) {
|
|
|
- if (!Check.isNull(date)) {
|
|
|
- String replace = date.replace("-", "");
|
|
|
- return Integer.valueOf(replace);
|
|
|
+ public static Integer getDateInteger(String date) {
|
|
|
+ if (!Check.isNull(date)) {
|
|
|
+ String replace = date.replace("-", "");
|
|
|
+ return Integer.valueOf(replace);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
- return null;
|
|
|
- }
|
|
|
|
|
|
- public static String getNowDate(String format) {
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat(format);
|
|
|
- Date date = new Date();
|
|
|
- return sdf.format(date);
|
|
|
- }
|
|
|
+ public static String getNowDate(String format) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(format);
|
|
|
+ Date date = new Date();
|
|
|
+ return sdf.format(date);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- public static String getAnotherDay(String format, String date, Integer num) {
|
|
|
+ public static String getAnotherDay(String format, String date, Integer num) {
|
|
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat(format);
|
|
|
- Date getDate = null;
|
|
|
- try {
|
|
|
- getDate = sdf.parse(date);
|
|
|
- } catch (ParseException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(format);
|
|
|
+ Date getDate = null;
|
|
|
+ try {
|
|
|
+ getDate = sdf.parse(date);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(getDate);
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, num);
|
|
|
+ Date resultDate = calendar.getTime();
|
|
|
+ return sdf.format(resultDate);
|
|
|
}
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(getDate);
|
|
|
- calendar.add(Calendar.DAY_OF_MONTH, num);
|
|
|
- Date resultDate = calendar.getTime();
|
|
|
- return sdf.format(resultDate);
|
|
|
- }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取两个时间中的每一天
|
|
|
+ *
|
|
|
+ * @param startTime
|
|
|
+ * @param endTime
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<String> getPerDay(String startTime, String endTime) {
|
|
|
+ //定义一个接受时间的集合
|
|
|
+ List<String> lDate = new ArrayList<>();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ try {
|
|
|
+ Date startDate = sdf.parse(startTime);
|
|
|
+ Date endDate = sdf.parse(endTime);
|
|
|
+ lDate.add(sdf.format(startDate));
|
|
|
+ Calendar calBegin = Calendar.getInstance();
|
|
|
+ // 使用给定的 Date 设置此 Calendar 的时间
|
|
|
+ calBegin.setTime(startDate);
|
|
|
+ Calendar calEnd = Calendar.getInstance();
|
|
|
+ // 使用给定的 Date 设置此 Calendar 的时间
|
|
|
+ calEnd.setTime(endDate);
|
|
|
+ // 测试此日期是否在指定日期之后
|
|
|
+ while (calEnd.getTime().after(calBegin.getTime())) {
|
|
|
+ // 根据日历的规则,为给定的日历字段添加或减去指定的时间量
|
|
|
+ calBegin.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ lDate.add(sdf.format(calBegin.getTime()));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("日期转换错误");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return lDate;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|