TimeExchange.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. package com.repair.common.utils;
  2. import com.repair.model.enumModel.eWeekStatu;
  3. import com.repair.model.pojo.UnitTimeHelpModel;
  4. import com.repair.model.vo.ClassSettingDateVo;
  5. import org.apache.commons.lang3.time.DateFormatUtils;
  6. import org.apache.commons.lang3.time.DateUtils;
  7. import java.sql.Timestamp;
  8. import java.text.DateFormat;
  9. import java.text.ParseException;
  10. import java.text.SimpleDateFormat;
  11. import java.time.DayOfWeek;
  12. import java.time.LocalDate;
  13. import java.time.LocalDateTime;
  14. import java.time.format.DateTimeFormatter;
  15. import java.time.temporal.ChronoUnit;
  16. import java.util.*;
  17. /**
  18. * 时间转化工具 date转为时间戳 时间戳转date 互相与String的转换
  19. * 所有出现的String time 格式都必须为(yyyy-MM-dd HH:mm:ss),否则出错
  20. *
  21. */
  22. public class TimeExchange {
  23. /**
  24. * String(yyyy-MM-dd HH:mm:ss) 转 Date
  25. *
  26. * @param time
  27. * @return
  28. * @throws ParseException
  29. */
  30. // String date = "2010/05/04 12:34:23";
  31. public static Date StringToDate(String time, String formatDate) throws ParseException {
  32. Date date = new Date();
  33. // 注意format的格式要与日期String的格式相匹配
  34. DateFormat dateFormat = new SimpleDateFormat(formatDate);
  35. try {
  36. date = dateFormat.parse(time);
  37. } catch (Exception e) {
  38. e.printStackTrace();
  39. }
  40. return date;
  41. }
  42. /**
  43. * Date转为String(yyyy-MM-dd HH:mm:ss)
  44. *
  45. * @param time
  46. * @return
  47. */
  48. public static String DateToString(Date time) {
  49. String dateStr = "";
  50. Date date = new Date();
  51. DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  52. try {
  53. dateStr = dateFormat.format(time);
  54. System.out.println(dateStr);
  55. } catch (Exception e) {
  56. e.printStackTrace();
  57. }
  58. return dateStr;
  59. }
  60. /**
  61. * String(yyyy-MM-dd HH:mm:ss)转10位时间戳
  62. *
  63. * @param time
  64. * @return
  65. */
  66. public static Integer StringToTimestamp(String time) {
  67. int times = 0;
  68. try {
  69. times = (int) ((Timestamp.valueOf(time).getTime()) / 1000);
  70. } catch (Exception e) {
  71. e.printStackTrace();
  72. }
  73. if (times == 0) {
  74. System.out.println("String转10位时间戳失败");
  75. }
  76. return times;
  77. }
  78. /**
  79. * 10位int型的时间戳转换为String(yyyy-MM-dd HH:mm:ss)
  80. *
  81. * @param time
  82. * @return
  83. */
  84. public static String timestampToString(Integer time) {
  85. //int转long时,先进行转型再进行计算,否则会是计算结束后在转型
  86. long temp = (long) time * 1000;
  87. Timestamp ts = new Timestamp(temp);
  88. String tsStr = "";
  89. DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  90. try {
  91. //方法一
  92. tsStr = dateFormat.format(ts);
  93. System.out.println(tsStr);
  94. } catch (Exception e) {
  95. e.printStackTrace();
  96. }
  97. return tsStr;
  98. }
  99. /**
  100. * 10位时间戳转Date
  101. *
  102. * @param time
  103. * @return
  104. */
  105. public static Date TimestampToDate(Integer time) {
  106. long temp = (long) time * 1000;
  107. Timestamp ts = new Timestamp(temp);
  108. Date date = new Date();
  109. try {
  110. date = ts;
  111. //System.out.println(date);
  112. } catch (Exception e) {
  113. e.printStackTrace();
  114. }
  115. return date;
  116. }
  117. /**
  118. * Date类型转换为10位时间戳
  119. *
  120. * @param time
  121. * @return
  122. */
  123. public static Integer DateToTimestamp(Date time) {
  124. Timestamp ts = new Timestamp(time.getTime());
  125. return (int) ((ts.getTime()) / 1000);
  126. }
  127. // 当前时间减1小时
  128. public static String TimeDesH(String time) throws ParseException {
  129. Calendar nowTime2 = Calendar.getInstance();
  130. nowTime2.setTime(StringToDate(time, "yyyy-MM-dd HH:mm:ss"));
  131. nowTime2.add(Calendar.HOUR, -1);
  132. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  133. return simpleDateFormat.format(nowTime2.getTime());
  134. }
  135. // 当前时间加5分钟
  136. public static String TimeRangeI(String time) throws ParseException {
  137. // 当前时间+5分钟
  138. Date endTime = DateUtils.addMinutes(StringToDate(time, "yyyy-MM-dd HH:mm:ss"), 300);
  139. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  140. return simpleDateFormat.format(endTime);
  141. }
  142. // 当前时间加2分钟
  143. public static String TimeRangeI10(String time, int m) throws ParseException {
  144. Calendar nowTime2 = Calendar.getInstance();
  145. nowTime2.setTime(StringToDate(time, "yyyy-MM-dd HH:mm:ss"));
  146. nowTime2.add(Calendar.SECOND, m);//10分钟前的时间
  147. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  148. return simpleDateFormat.format(nowTime2.getTime());
  149. }
  150. // 当前时间减5分钟
  151. public static String TimeRangeD(String time) throws ParseException {
  152. Calendar nowTime2 = Calendar.getInstance();
  153. nowTime2.setTime(StringToDate(time, "yyyy-MM-dd HH:mm:ss"));
  154. nowTime2.add(Calendar.MINUTE, -300);//5分钟前的时间
  155. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  156. return simpleDateFormat.format(nowTime2.getTime());
  157. }
  158. // 获取当前日期
  159. public static String getDate() {
  160. SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd");
  161. return sp.format(new Date());
  162. }
  163. // 获取当前日期的年月
  164. public static String getDateMonth() {
  165. SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-");
  166. return sp.format(new Date());
  167. }
  168. // 获取前天
  169. public static String getQianDay() throws ParseException {
  170. Calendar nowTime2 = Calendar.getInstance();
  171. nowTime2.setTime(StringToDate(getTime(), "yyyy-MM-dd HH:mm:ss"));
  172. nowTime2.add(Calendar.DATE, -5);//5分钟前的时间
  173. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  174. return simpleDateFormat.format(nowTime2.getTime());
  175. }
  176. // 获取当前时间
  177. public static String getTime() {
  178. SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  179. return sp.format(new Date());
  180. }
  181. public static String getOnlyMM() {
  182. SimpleDateFormat sp = new SimpleDateFormat("HH:mm");
  183. return sp.format(new Date());
  184. }
  185. public static String getOnlyDesMM() throws ParseException {
  186. Calendar nowTime2 = Calendar.getInstance();
  187. nowTime2.setTime(StringToDate(getTime(), "yyyy-MM-dd HH:mm:ss"));
  188. nowTime2.add(Calendar.MINUTE, -5);//5分钟前的时间
  189. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
  190. return simpleDateFormat.format(nowTime2.getTime());
  191. }
  192. public static String getYear() {
  193. SimpleDateFormat sp = new SimpleDateFormat("yyyy");
  194. return sp.format(new Date());
  195. }
  196. public static String getMonth() {
  197. SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM");
  198. return sp.format(new Date());
  199. }
  200. // 获取当前时间
  201. public static String getOnlyTime() {
  202. SimpleDateFormat sp = new SimpleDateFormat("HH:mm:ss");
  203. return sp.format(new Date());
  204. }
  205. /**
  206. * 计算两个日期的时间差
  207. *
  208. * @param time1
  209. * @param time2
  210. * @return
  211. */
  212. public static double getTimeDifference(String time1, String time2) {
  213. SimpleDateFormat timeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  214. long t1 = 0L;
  215. long t2 = 0L;
  216. try {
  217. t1 = timeformat.parse(time1).getTime();
  218. } catch (ParseException e) {
  219. // TODO Auto-generated catch block
  220. e.printStackTrace();
  221. }
  222. try {
  223. t2 = timeformat.parse(time2).getTime();
  224. } catch (ParseException e) {
  225. // TODO Auto-generated catch block
  226. e.printStackTrace();
  227. }
  228. //因为t1-t2得到的是毫秒级,所以要初3600000得出小时.算天数或秒同理
  229. double hours = (double) ((t2 - t1) / 3600000);
  230. double minutes = (double) (((t2 - t1) / 1000 - hours * 3600) / 60 / 60);
  231. return hours + minutes;
  232. }
  233. public static double getOnlyTimeDifference(String time1, String time2) {
  234. SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
  235. long t1 = 0L;
  236. long t2 = 0L;
  237. try {
  238. t1 = timeformat.parse(time1).getTime();
  239. } catch (ParseException e) {
  240. // TODO Auto-generated catch block
  241. e.printStackTrace();
  242. }
  243. try {
  244. t2 = timeformat.parse(time2).getTime();
  245. } catch (ParseException e) {
  246. // TODO Auto-generated catch block
  247. e.printStackTrace();
  248. }
  249. //因为t1-t2得到的是毫秒级,所以要初3600000得出小时.算天数或秒同理
  250. double hours = (double) ((t2 - t1) / 3600000);
  251. double minutes = (double) (((t2 - t1) / 1000 - hours * 3600) / 60 / 60);
  252. return hours + minutes;
  253. }
  254. public static double getDiff(String str1, String str2) {
  255. return str2.compareTo(str1);
  256. }
  257. /**
  258. * 时间减去分钟数
  259. *
  260. * @param time 时间
  261. * @param FormatStr 时间格式
  262. * @param amount 要加减的时间(单位为分钟)
  263. * @return
  264. * @throws ParseException
  265. */
  266. public static String TimeRangeMinute(String time, int amount, String FormatStr) throws ParseException {
  267. Date endTime = DateUtils.addMinutes(ShortStringToDate(time, FormatStr), amount);
  268. SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FormatStr);
  269. return simpleDateFormat.format(endTime);
  270. }
  271. /**
  272. * 时间减去小时数
  273. *
  274. * @param time 时间
  275. * @param FormatStr 时间格式
  276. * @param amount 要加减的时间(单位为小时)
  277. * @return
  278. * @throws ParseException
  279. */
  280. public static String TimeRangeHour(Date time, int amount, String FormatStr) {
  281. Date endTime = DateUtils.addHours(time, amount);
  282. SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FormatStr);
  283. return simpleDateFormat.format(endTime);
  284. }
  285. /**
  286. * String 转 Date
  287. *
  288. * @param time 时间
  289. * @param formatStr 自定义时间格式
  290. * @return
  291. * @throws ParseException
  292. */
  293. public static Date ShortStringToDate(String time, String formatStr) throws ParseException {
  294. Date date = new Date();
  295. // 注意format的格式要与日期String的格式相匹配
  296. DateFormat dateFormat = new SimpleDateFormat(formatStr);
  297. try {
  298. date = dateFormat.parse(time);
  299. System.out.println(date.toString());
  300. } catch (Exception e) {
  301. e.printStackTrace();
  302. }
  303. return date;
  304. }
  305. /**
  306. * Date转为String
  307. *
  308. * @param time 时间
  309. * @param FormatStr 自定义时间格式
  310. * @return
  311. */
  312. public static String DateToString(Date time, String FormatStr) {
  313. String dateStr = "";
  314. DateFormat dateFormat = new SimpleDateFormat(FormatStr);
  315. try {
  316. dateStr = dateFormat.format(time);
  317. } catch (Exception e) {
  318. e.printStackTrace();
  319. }
  320. return dateStr;
  321. }
  322. /**
  323. * 日期路径 即年/月/日 如2018/08/08
  324. */
  325. public static final String datePath() {
  326. Date now = new Date();
  327. return DateFormatUtils.format(now, "yyyy/MM/dd");
  328. }
  329. /**
  330. * 比较时间1是否小于时间2
  331. * 如果时间1小于时间2,接口返回true
  332. * 如果时间1大于时间2,接口返回false
  333. *
  334. * @param dateOne 时间1
  335. * @param dateTwo 时间2
  336. * @param Forma 时间格式
  337. * @return
  338. * @throws ParseException
  339. */
  340. public static boolean CompareDate(String dateOne, String dateTwo, String Forma) throws ParseException {
  341. SimpleDateFormat df = new SimpleDateFormat(Forma);
  342. Date sd1 = df.parse(dateOne);
  343. Date sd2 = df.parse(dateTwo);
  344. return sd1.before(sd2);
  345. }
  346. public static LocalDateTime StringToLocalTime(String time, String formatStr){
  347. //1.具有转换功能的对象
  348. DateTimeFormatter df = DateTimeFormatter.ofPattern(formatStr);
  349. //3.LocalDate发动,将字符串转换成  df格式的LocalDateTime对象,的功能
  350. LocalDateTime LocalTime = LocalDateTime.parse(time,df);
  351. return LocalTime;
  352. }
  353. /**
  354. * 获取一周的开始时间和结束时间
  355. * 获取本周星期一作为一周的第一天的起始时间和结束时间
  356. *
  357. * @return 返回的数据中第一个是开始时间 第二个是结束时间
  358. */
  359. public static String[] getCurrentWeekTimeFrame() {
  360. Calendar calendar = Calendar.getInstance();
  361. calendar.setTimeZone(TimeZone.getTimeZone("GMT+8"));
  362. //start of the week
  363. if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
  364. calendar.add(Calendar.DAY_OF_YEAR, -1);
  365. }
  366. calendar.add(Calendar.DAY_OF_WEEK, -(calendar.get(Calendar.DAY_OF_WEEK) - 2));
  367. //给0的时候查不出数据
  368. // calendar.set(Calendar.HOUR_OF_DAY, 0);
  369. // calendar.set(Calendar.MINUTE, 0);
  370. // calendar.set(Calendar.SECOND, 0);
  371. // calendar.set(Calendar.MILLISECOND, 0);
  372. String startTime = DateToString(calendar.getTime(), "yyyy-MM-dd");
  373. //end of the week
  374. calendar.add(Calendar.DAY_OF_WEEK, 6);
  375. calendar.set(Calendar.HOUR_OF_DAY, 23);
  376. calendar.set(Calendar.MINUTE, 59);
  377. calendar.set(Calendar.SECOND, 59);
  378. calendar.set(Calendar.MILLISECOND, 999);
  379. String endTime = DateToString(calendar.getTime(), "yyyy-MM-dd");
  380. return new String[]{startTime, endTime};
  381. }
  382. /**
  383. * 获取指定月份有多少天
  384. *
  385. * @param month
  386. * @return
  387. */
  388. public static int getMonthDays(String date, int month) {
  389. int year = Integer.valueOf(date.substring(0, 3));
  390. int[] arr = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  391. int day = arr[month - 1];//天数对应=数组-1
  392. if (month == 2 && year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
  393. day = 29;
  394. }
  395. return day;
  396. }
  397. /**
  398. * 获取指定月份的第一天和最后一天
  399. *
  400. * @param DateStr 指定月份
  401. * @return 返回的数据中第一个是开始时间 第二个是结束时间
  402. */
  403. public static String[] getCurrentMonthTimeFrame(String DateStr) {
  404. Calendar c = Calendar.getInstance();//获取Calendar实例
  405. c.set(Calendar.YEAR, Integer.parseInt(DateStr.substring(0, 4)));
  406. c.set(Calendar.MONTH, Integer.parseInt(DateStr.substring(5, 7).replace("-", "")) - 1);
  407. c.set(Calendar.DAY_OF_MONTH, 1);
  408. String startDate = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
  409. int lastDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);
  410. c.set(Calendar.DAY_OF_MONTH, lastDay);
  411. String endDate = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()) + " 23:59:59";
  412. return new String[]{startDate, endDate};
  413. }
  414. //region 获取某一天的开始时间
  415. public static String getStartOfDayStr(Date date) {
  416. Calendar calendar = Calendar.getInstance();
  417. calendar.setTime(date);
  418. int year = calendar.get(Calendar.YEAR);
  419. int month = calendar.get(Calendar.MONTH);
  420. int day = calendar.get(Calendar.DATE);
  421. calendar.setTimeInMillis(0);
  422. calendar.set(year, month, day, 0, 0, 0);
  423. return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
  424. }
  425. //endregion
  426. //region 获取某一天的结束时间
  427. public static String getEndOfDayStr(Date date) {
  428. Calendar calendar = Calendar.getInstance();
  429. calendar.setTime(date);
  430. int year = calendar.get(Calendar.YEAR);
  431. int month = calendar.get(Calendar.MONTH);
  432. int day = calendar.get(Calendar.DATE);
  433. calendar.setTimeInMillis(0);
  434. calendar.set(year, month, day, 23, 59, 59);
  435. return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
  436. }
  437. //endregion
  438. //region 获取指定月份的最后一天
  439. public static Date getToMonthEndDate(String DateStr) {
  440. Calendar c = Calendar.getInstance();
  441. c.clear();
  442. c.set(Calendar.YEAR, Integer.parseInt(DateStr.substring(0, 4)));
  443. c.set(Calendar.MONTH, Integer.parseInt(DateStr.substring(5, 7).replace("-", "")) - 1);
  444. c.roll(Calendar.DAY_OF_MONTH, -1);
  445. c.set(Calendar.HOUR_OF_DAY, 23);
  446. c.set(Calendar.MINUTE, 59);
  447. c.set(Calendar.SECOND, 59);
  448. c.set(Calendar.MILLISECOND, 999);
  449. return c.getTime();
  450. }
  451. //endregion
  452. //region 获取指定月份的第一天
  453. public static Date getToMonthBeginDate(String DateStr) {
  454. Calendar c = Calendar.getInstance();
  455. c.clear();
  456. c.set(Calendar.YEAR, Integer.parseInt(DateStr.substring(0, 4)));
  457. c.set(Calendar.MONTH, Integer.parseInt(DateStr.substring(5, 7).replace("-", "")) - 1);
  458. c.set(Calendar.HOUR_OF_DAY, 0);
  459. c.set(Calendar.MINUTE, 0);
  460. c.set(Calendar.SECOND, 0);
  461. c.set(Calendar.MILLISECOND, 000);
  462. return c.getTime();
  463. }
  464. //endregion
  465. //region 获取某一天的开始时间
  466. public static Date getStartOfDay(Date date) {
  467. Calendar calendar = Calendar.getInstance();
  468. calendar.setTime(date);
  469. int year = calendar.get(Calendar.YEAR);
  470. int month = calendar.get(Calendar.MONTH);
  471. int day = calendar.get(Calendar.DATE);
  472. calendar.set(year, month, day, 0, 0, 0);
  473. calendar.set(Calendar.MILLISECOND, 000);
  474. return calendar.getTime();
  475. }
  476. //endregion
  477. //region 获取某一天的结束时间
  478. public static Date getEndOfDay(Date date) {
  479. Calendar calendar = Calendar.getInstance();
  480. calendar.setTime(date);
  481. int year = calendar.get(Calendar.YEAR);
  482. int month = calendar.get(Calendar.MONTH);
  483. int day = calendar.get(Calendar.DATE);
  484. calendar.setTimeInMillis(0);
  485. calendar.set(year, month, day, 23, 59, 59);
  486. return calendar.getTime();
  487. }
  488. //endregion
  489. public static List<UnitTimeHelpModel> MonthArrayTime(Date StartDate, Date EndDate) {
  490. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//格式化为年月
  491. Calendar StartTime = Calendar.getInstance();
  492. StartTime.setTime(StartDate);
  493. StartTime.set(StartTime.get(Calendar.YEAR), StartTime.get(Calendar.MONTH), StartTime.get(Calendar.DATE));
  494. Calendar EndTime = Calendar.getInstance();
  495. EndTime.setTime(EndDate);
  496. EndTime.set(EndTime.get(Calendar.YEAR), EndTime.get(Calendar.MONTH), EndTime.get(Calendar.DATE));
  497. int total = (EndTime.get(Calendar.YEAR) - StartTime.get(Calendar.YEAR)) * 12 + (EndTime.get(Calendar.MONTH) - StartTime.get(Calendar.MONTH));
  498. List<UnitTimeHelpModel> result = new ArrayList() {
  499. };
  500. for (int i = 0; i <= total; i++) {
  501. StartTime.add(Calendar.MONTH, i == 0 ? 0 : 1);
  502. Date MonthLastDay = getToMonthEndDate(sdf.format(StartTime.getTime()));
  503. UnitTimeHelpModel data = new UnitTimeHelpModel();
  504. data.setStartDate(i == 0 ? StartTime.getTime() : getStartOfDay(getToMonthBeginDate(sdf.format(StartTime.getTime()))));
  505. data.setEndDate(EndTime.getTime().before(MonthLastDay) ? getEndOfDay(EndTime.getTime()) : MonthLastDay);
  506. result.add(data);
  507. }
  508. return result;
  509. }
  510. public static List<ClassSettingDateVo> getDatesBetween(LocalDate startDate, LocalDate endDate) {
  511. List<ClassSettingDateVo> datas = new ArrayList<>();
  512. long numOfDaysBetween = ChronoUnit.DAYS.between(startDate, endDate);
  513. for (int i = 0; i <= numOfDaysBetween; i++) {
  514. ClassSettingDateVo data = new ClassSettingDateVo();
  515. LocalDate date = startDate.plusDays(i);
  516. // 获取当前日期对应的星期几
  517. DayOfWeek dow = date.getDayOfWeek();
  518. int dayOfWeek = dow.getValue(); // 获取星期几的数字表示,1表示周一,7表示周日
  519. data.setWeekStr(eWeekStatu.stringOf(dayOfWeek));
  520. data.setWeek(dayOfWeek);
  521. data.setDateStr(date.toString());
  522. datas.add(data);
  523. }
  524. return datas;
  525. }
  526. /**
  527. * 获取时间date1与date2相差的秒数
  528. *
  529. * @param date1 起始时间
  530. * @param date2 结束时间
  531. * @return 返回相差的秒数
  532. */
  533. public static int getOffsetSeconds(Date date1, Date date2) {
  534. int seconds = (int) ((date2.getTime() - date1.getTime()) / 1000);
  535. return seconds;
  536. }
  537. /**
  538. * 获取时间date1与date2相差的分钟数
  539. *
  540. * @param date1 起始时间
  541. * @param date2 结束时间
  542. * @return 返回相差的分钟数
  543. */
  544. public static int getOffsetMinutes(Date date1, Date date2) {
  545. return getOffsetSeconds(date1, date2) / 60;
  546. }
  547. /**
  548. * 获取时间date1与date2相差的小时数
  549. *
  550. * @param date1 起始时间
  551. * @param date2 结束时间
  552. * @return 返回相差的小时数
  553. */
  554. public static int getOffsetHours(Date date1, Date date2) {
  555. return getOffsetMinutes(date1, date2) / 60;
  556. }
  557. /**
  558. * 获取时间date1与date2相差的天数数
  559. *
  560. * @param date1 起始时间
  561. * @param date2 结束时间
  562. * @return 返回相差的天数
  563. */
  564. public static int getOffsetDays(Date date1, Date date2) {
  565. return getOffsetHours(date1, date2) / 24+1;
  566. }
  567. public static boolean overlapping(String start1,String end1,String start2,String end2) throws ParseException {
  568. boolean one = CompareDate(start1,end2,"HH:mm");
  569. boolean two = CompareDate(start2,end1,"HH:mm");
  570. return (one && two);
  571. }
  572. public static void main(String[] args) throws ParseException {
  573. Integer userId = 0;
  574. String ss = userId.toString();
  575. System.out.println(ss);
  576. }
  577. }