DateUtil.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. package platform.common.util;
  2. import java.text.DateFormat;
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.*;
  6. import org.apache.commons.lang3.StringUtils;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import platform.modules.sys.service.SysConfigService;
  9. import javax.annotation.PostConstruct;
  10. /**
  11. * Created by luohaifeng on 2017/8/9.
  12. */
  13. public class DateUtil {
  14. public static String YYYY_MM_DD = "yyyy-MM-dd";
  15. public static String YYYY_MM = "yyyy-MM";
  16. public static String getCurrentDateString(String fmt) {
  17. SimpleDateFormat sdf = new SimpleDateFormat(fmt);
  18. return sdf.format(new Date());
  19. }
  20. public static String getCurrentDateString() {
  21. return getCurrentDateString(YYYY_MM_DD);
  22. }
  23. /**
  24. * 日期转字符串
  25. *
  26. * @param date
  27. * @return
  28. */
  29. public static String getTimeString(Date date) {
  30. if (null == date) {
  31. return "";
  32. } else {
  33. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  34. return simpleDateFormat.format(date);
  35. }
  36. }
  37. // 获取当前时间
  38. public static Date getNowDate() {
  39. TimeZone time = TimeZone.getTimeZone("Asia/Shanghai");
  40. TimeZone.setDefault(time);
  41. Date now = new Date();
  42. return now;
  43. }
  44. public static String getTime(Date date) {
  45. if (null == date) {
  46. return "";
  47. } else {
  48. SimpleDateFormat simpleDateFormat = new SimpleDateFormat(YYYY_MM_DD);
  49. return simpleDateFormat.format(date);
  50. }
  51. }
  52. /**
  53. * 日期转字符串 yyyy-MM-dd
  54. *
  55. * @param date
  56. * @return
  57. */
  58. public static String getTimeStringShort(Date date) {
  59. if (null == date) {
  60. return "";
  61. } else {
  62. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  63. return simpleDateFormat.format(date);
  64. }
  65. }
  66. /**
  67. * 字符串转时间转换日期格式
  68. *
  69. * @param date 时间字符串
  70. * @param pattern 字符串时间格式
  71. * @return
  72. * @throws ParseException
  73. */
  74. public static Date parseTimeStringToDate(String date, String pattern) throws ParseException {
  75. if (null == date) {
  76. return null;
  77. } else {
  78. SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
  79. return simpleDateFormat.parse(date);
  80. }
  81. }
  82. public static long getDay(String pay_time, Integer cycle) throws ParseException {
  83. Date date = DateUtil.parseTimeStringToDate(pay_time, DateUtil.YYYY_MM_DD);
  84. Calendar calendar = Calendar.getInstance();
  85. calendar.setTime(date);
  86. calendar.add(Calendar.MONTH, -cycle);
  87. return (date.getTime() - calendar.getTimeInMillis()) / (24 * 60 * 60 * 1000);
  88. }
  89. public static Boolean isGenerate(String pay_time, Integer remind) throws ParseException {
  90. if (null == remind) {
  91. remind = 5;
  92. }
  93. Date date = DateUtil.parseTimeStringToDate(pay_time, DateUtil.YYYY_MM_DD);
  94. Calendar calendar = Calendar.getInstance();
  95. calendar.setTime(date);
  96. calendar.add(Calendar.DATE, -remind);
  97. if (calendar.getTimeInMillis() <= new Date().getTime()) {
  98. return true;
  99. }
  100. return false;
  101. }
  102. /**
  103. * 2017-08-19 20:30
  104. *
  105. * @return
  106. */
  107. public static String[] getDate(String time) {
  108. String[] strs = time.split(":");
  109. return strs;
  110. }
  111. public static String getPayTime(Integer payment_cycle, String contract_start_date) throws ParseException {
  112. Calendar plan = Calendar.getInstance();
  113. plan.setTime(parseTimeStringToDate(contract_start_date, YYYY_MM_DD));
  114. plan.add(Calendar.MONTH, payment_cycle);
  115. return getTimeStringShort(plan.getTime());
  116. }
  117. public static String AddMonth(Integer month, String date) throws ParseException {
  118. Calendar plan = Calendar.getInstance();
  119. plan.setTime(parseTimeStringToDate(date, YYYY_MM_DD));
  120. plan.add(Calendar.MONTH, month);
  121. return getTimeStringShort(plan.getTime());
  122. }
  123. public static String getCurrentMonth() throws ParseException {
  124. Calendar plan = Calendar.getInstance();
  125. plan.setTime(new Date());
  126. return String.valueOf(plan.get(Calendar.MONTH) + 1);
  127. }
  128. public static String getCurrentYear() throws ParseException {
  129. Calendar plan = Calendar.getInstance();
  130. plan.setTime(new Date());
  131. return String.valueOf(plan.get(Calendar.YEAR));
  132. }
  133. public static String getMonthStart(String date) throws ParseException {
  134. Calendar plan = Calendar.getInstance();
  135. plan.setTime(parseTimeStringToDate(date, YYYY_MM));
  136. plan.add(Calendar.MONTH, 0);
  137. plan.set(Calendar.DAY_OF_MONTH, 1);
  138. return getTime(plan.getTime());
  139. }
  140. public static String getMonthEnd(String date) throws ParseException {
  141. Calendar plan = Calendar.getInstance();
  142. plan.setTime(parseTimeStringToDate(date, YYYY_MM));
  143. plan.add(Calendar.MONTH, 1);
  144. plan.set(Calendar.DAY_OF_MONTH, 0);
  145. return getTime(plan.getTime());
  146. }
  147. public static Boolean compareTo(String time1, String time2) throws ParseException {
  148. Date date1 = DateUtil.parseTimeStringToDate(time1, YYYY_MM_DD);
  149. Date date2 = DateUtil.parseTimeStringToDate(time2, YYYY_MM_DD);
  150. if (date1.getTime() - date2.getTime() >= 0) {
  151. return true;
  152. } else {
  153. return false;
  154. }
  155. }
  156. public static void main(String args[]) {
  157. try {
  158. System.out.println(getCurrentMonth());
  159. System.out.println(getCurrentYear());
  160. } catch (ParseException e) {
  161. e.printStackTrace();
  162. }
  163. }
  164. /**
  165. * 两个日期之间的天数
  166. *
  167. * @param date1
  168. * @param date2
  169. * @return
  170. * @throws ParseException
  171. */
  172. public static int getDateSpace(String date1, String date2)
  173. throws ParseException {
  174. Calendar calst = Calendar.getInstance();
  175. ;
  176. Calendar caled = Calendar.getInstance();
  177. calst.setTime(DateUtil.parseTimeStringToDate(date1, YYYY_MM_DD));
  178. caled.setTime(DateUtil.parseTimeStringToDate(date2, YYYY_MM_DD));
  179. //设置时间为0时
  180. calst.set(Calendar.HOUR_OF_DAY, 0);
  181. calst.set(Calendar.MINUTE, 0);
  182. calst.set(Calendar.SECOND, 0);
  183. caled.set(Calendar.HOUR_OF_DAY, 0);
  184. caled.set(Calendar.MINUTE, 0);
  185. caled.set(Calendar.SECOND, 0);
  186. //得到两个日期相差的天数
  187. int days = ((int) (caled.getTime().getTime() / 1000) - (int) (calst.getTime().getTime() / 1000)) / 3600 / 24;
  188. return days;
  189. }
  190. //获取审核剩余时间 审核时间5天
  191. public static String getOverTimeStr(String create_time, Integer overDay) throws ParseException {
  192. String overTimeStr = "";
  193. if (null == overDay) {
  194. overDay = 5;
  195. }
  196. if (StringUtils.isNotBlank(create_time)) {
  197. Calendar overTime = Calendar.getInstance();
  198. Calendar now = Calendar.getInstance();
  199. overTime.setTime(DateUtil.parseTimeStringToDate(create_time, "yyyy-MM-dd HH:mm:ss"));
  200. overTime.add(Calendar.DATE, overDay);
  201. now.setTime(new Date());
  202. overTime.set(Calendar.MINUTE, 0);
  203. overTime.set(Calendar.SECOND, 0);
  204. now.set(Calendar.MINUTE, 0);
  205. now.set(Calendar.SECOND, 0);
  206. //得到两个日期相差的小时数
  207. int hours = ((int) (overTime.getTime().getTime() / 1000) - (int) (now.getTime().getTime() / 1000)) / 3600;
  208. if (hours / 24 > 0) {
  209. overTimeStr = "剩余" + String.valueOf((int) Math.floor(hours / 24)) + "个工作日";//+(hours%24)+"小时";
  210. } else {
  211. overTimeStr = "超出" + String.valueOf((-1) * (int) Math.floor(hours / 24)) + "个工作日";//+(hours%24)+"小时";
  212. }
  213. }
  214. return overTimeStr;
  215. }
  216. //获取审核处理时间 审核时间5天
  217. public static String getDealTimeStr(String create_time, String deal_time, Integer overDay) throws ParseException {
  218. String overTimeStr = "";
  219. if (null == overDay) {
  220. overDay = 5;
  221. }
  222. if (StringUtils.isNotBlank(create_time) && StringUtils.isNotBlank(deal_time)) {
  223. Calendar overTime = Calendar.getInstance();
  224. Calendar dealTime = Calendar.getInstance();
  225. overTime.setTime(DateUtil.parseTimeStringToDate(create_time, "yyyy-MM-dd HH:mm:ss"));
  226. overTime.add(Calendar.DATE, overDay);
  227. dealTime.setTime(DateUtil.parseTimeStringToDate(deal_time, "yyyy-MM-dd HH:mm:ss"));
  228. overTime.set(Calendar.MINUTE, 0);
  229. overTime.set(Calendar.SECOND, 0);
  230. dealTime.set(Calendar.MINUTE, 0);
  231. dealTime.set(Calendar.SECOND, 0);
  232. //得到两个日期相差的小时数
  233. int hours = ((int) (overTime.getTime().getTime() / 1000) - (int) (dealTime.getTime().getTime() / 1000)) / 3600;
  234. if (hours / 24 > 0) {
  235. overTimeStr = "提前" + String.valueOf((int) Math.floor(hours / 24)) + "个工作日完成";//+(hours%24)+"小时完成";
  236. } else {
  237. overTimeStr = "超出" + String.valueOf((-1) * (int) Math.floor(hours / 24)) + "个工作日完成";//+(hours%24)+"小时完成";
  238. }
  239. }
  240. return overTimeStr;
  241. }
  242. //5秒内不能重复同一请求
  243. public static boolean isFrequent(String time) throws ParseException {
  244. Date preTime = DateUtil.parseTimeStringToDate(time, "yyyy-MM-dd HH:mm:ss");
  245. Date currTime = new Date();
  246. if (currTime.getTime() - preTime.getTime() < 5000) {
  247. return true;
  248. }
  249. return false;
  250. }
  251. public static String getDayStart(String datetime) throws ParseException {
  252. if (CommonUtils.isNull(datetime)) {
  253. return null;
  254. } else {
  255. Date date = parseTimeStringToDate(datetime.substring(0, 10), YYYY_MM_DD);
  256. String dayStart = datetime.substring(0, 10) + " 00:00:00";
  257. return dayStart;
  258. }
  259. }
  260. public static String getDayEnd(String datetime) throws ParseException {
  261. if (CommonUtils.isNull(datetime)) {
  262. return null;
  263. } else {
  264. Date date = parseTimeStringToDate(datetime.substring(0, 10), YYYY_MM_DD);
  265. String dayEnd = datetime.substring(0, 10) + " 23:59:59";
  266. return dayEnd;
  267. }
  268. }
  269. public static String getTomorrow() {
  270. Date date = new Date();
  271. Calendar calendar = Calendar.getInstance();
  272. calendar.setTime(date);
  273. calendar.add(5, 1);
  274. date = calendar.getTime();
  275. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  276. String dateString = formatter.format(date);
  277. return dateString;
  278. }
  279. public static String getAfterDayDate(int len) {
  280. Date date = new Date();
  281. Calendar calendar = Calendar.getInstance();
  282. calendar.setTime(date);
  283. calendar.add(5, len);
  284. date = calendar.getTime();
  285. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  286. String dateString = formatter.format(date);
  287. return dateString;
  288. }
  289. // 获得当天0点时间
  290. public static Date getTimesmorning() {
  291. Calendar cal = Calendar.getInstance();
  292. cal.set(Calendar.HOUR_OF_DAY, 0);
  293. cal.set(Calendar.SECOND, 0);
  294. cal.set(Calendar.MINUTE, 0);
  295. cal.set(Calendar.MILLISECOND, 0);
  296. return cal.getTime();
  297. }
  298. // 获得当天24点时间
  299. public static Date getTimesnight() {
  300. Calendar cal = Calendar.getInstance();
  301. cal.set(Calendar.HOUR_OF_DAY, 24);
  302. cal.set(Calendar.SECOND, 0);
  303. cal.set(Calendar.MINUTE, 0);
  304. cal.set(Calendar.MILLISECOND, 0);
  305. return cal.getTime();
  306. }
  307. // 获得本周一0点时间
  308. public static Date getTimesWeekmorning() {
  309. Calendar cal = Calendar.getInstance();
  310. cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
  311. cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
  312. return cal.getTime();
  313. }
  314. // 获得本周日24点时间
  315. public static Date getTimesWeeknight() {
  316. Calendar cal = Calendar.getInstance();
  317. cal.setTime(getTimesWeekmorning());
  318. cal.add(Calendar.DAY_OF_WEEK, 7);
  319. return cal.getTime();
  320. }
  321. // 获得本月第一天0点时间
  322. public static Date getTimesMonthmorning() {
  323. Calendar cal = Calendar.getInstance();
  324. cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
  325. cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
  326. return cal.getTime();
  327. }
  328. // 获得本月最后一天24点时间
  329. public static Date getTimesMonthnight() {
  330. Calendar cal = Calendar.getInstance();
  331. cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
  332. cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
  333. cal.set(Calendar.HOUR_OF_DAY, 24);
  334. return cal.getTime();
  335. }
  336. /**
  337. * 获取两个日期相差的月数
  338. */
  339. public static int getMonthDiff(Date d1, Date d2) {
  340. Calendar c1 = Calendar.getInstance();
  341. Calendar c2 = Calendar.getInstance();
  342. c1.setTime(d1);
  343. c2.setTime(d2);
  344. int year1 = c1.get(Calendar.YEAR);
  345. int year2 = c2.get(Calendar.YEAR);
  346. int month1 = c1.get(Calendar.MONTH);
  347. int month2 = c2.get(Calendar.MONTH);
  348. int day1 = c1.get(Calendar.DAY_OF_MONTH);
  349. int day2 = c2.get(Calendar.DAY_OF_MONTH);
  350. // 获取年的差值 
  351. int yearInterval = year1 - year2;
  352. // 如果 d1的 月-日 小于 d2的 月-日 那么 yearInterval-- 这样就得到了相差的年数
  353. if (month1 < month2 || month1 == month2 && day1 < day2) {
  354. yearInterval--;
  355. }
  356. // 获取月数差值
  357. int monthInterval = (month1 + 12) - month2;
  358. if (day1 < day2) {
  359. monthInterval--;
  360. }
  361. monthInterval %= 12;
  362. int monthsDiff = Math.abs(yearInterval * 12 + monthInterval);
  363. return monthsDiff;
  364. }
  365. public static String getTimeDiffStr(String startDate, int days) {
  366. try {
  367. DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  368. Date d1 = null;
  369. Date beginDate = df.parse(startDate);
  370. Calendar calendar = Calendar.getInstance();
  371. calendar.setTime(beginDate);
  372. calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + days);
  373. Date endDate = df.parse(df.format(calendar.getTime()));
  374. d1 = endDate;
  375. Date d2 = new Date();
  376. long date = d1.getTime() - d2.getTime();
  377. long day = date / (1000 * 60 * 60 * 24);
  378. long hour = (date / (1000 * 60 * 60) - day * 24);
  379. long min = ((date / (60 * 1000)) - day * 24 * 60 - hour * 60);
  380. long s = (date / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
  381. day = day < 0 ? 0 : day;
  382. hour = hour < 0 ? 0 : hour;
  383. min = min < 0 ? 0 : min;
  384. s = s < 0 ? 0 : s;
  385. return "" + day + "天" + hour + "小时" + min + "分" /*+ s + "秒"*/;
  386. } catch (ParseException e) {
  387. e.printStackTrace();
  388. }
  389. return "";
  390. }
  391. //
  392. public static String getTimeDiff(String create_time, String deal_time, Integer overDay, String holiday) throws ParseException {
  393. String overTimeStr = "";
  394. if (null == overDay) {
  395. overDay = 5;
  396. }
  397. if (deal_time != null && deal_time != "") {
  398. if (StringUtils.isNotBlank(create_time) && StringUtils.isNotBlank(deal_time)) {
  399. Calendar overTime = Calendar.getInstance();
  400. Calendar dealTime = Calendar.getInstance();
  401. // overTime.setTime(DateUtil.parseTimeStringToDate(create_time, "yyyy-MM-dd HH:mm:ss"));
  402. // overTime.add(Calendar.DATE, overDay);
  403. // overTime.set(Calendar.MINUTE, 0);
  404. // overTime.set(Calendar.SECOND, 0);
  405. int i = 0, j = 0;
  406. while (i < overDay) {
  407. j++;
  408. overTime.setTime(DateUtil.parseTimeStringToDate(create_time, "yyyy-MM-dd HH:mm:ss"));
  409. overTime.add(Calendar.DATE, j);
  410. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMdd");
  411. String deadline = simpleDateFormat.format(overTime.getTime());
  412. if (!holiday.contains(deadline)) {
  413. i++;
  414. }
  415. }
  416. overTime.set(Calendar.HOUR_OF_DAY, 23);
  417. overTime.set(Calendar.MINUTE, 0);
  418. overTime.set(Calendar.SECOND, 0);
  419. dealTime.setTime(DateUtil.parseTimeStringToDate(deal_time, "yyyy-MM-dd HH:mm:ss"));
  420. dealTime.set(Calendar.MINUTE, 0);
  421. dealTime.set(Calendar.SECOND, 0);
  422. String deadline = getTimeString(overTime.getTime());
  423. String dealDate = getTimeString(dealTime.getTime());
  424. //得到两个日期相差的小时数
  425. int hours = ((int) (overTime.getTime().getTime() / 1000) - (int) (dealTime.getTime().getTime() / 1000)) / 3600;
  426. if (hours > 24) {
  427. int count = (int) Math.floor(hours / 24);
  428. List<String> days = getDays(dealDate, deadline, "yyyy-MM-dd HH:mm:ss", "MMdd");
  429. for (String day : days) {
  430. if (holiday.contains(day)) {
  431. count--;
  432. }
  433. }
  434. overTimeStr = "提前" + count + "个工作日完成";
  435. } else {
  436. int count = (int) Math.abs(Math.ceil(hours / 24));
  437. List<String> days = getDays(deadline, dealDate, "yyyy-MM-dd HH:mm:ss", "MMdd");
  438. for (String day : days) {
  439. if (holiday.contains(day)) {
  440. count--;
  441. }
  442. }
  443. overTimeStr = "超出" + count + "个工作日完成";
  444. }
  445. }
  446. return overTimeStr;
  447. } else {
  448. if (StringUtils.isNotBlank(create_time)) {
  449. Calendar overTime = Calendar.getInstance();
  450. Calendar now = Calendar.getInstance();
  451. // overTime.setTime(DateUtil.parseTimeStringToDate(create_time, "yyyy-MM-dd HH:mm:ss"));
  452. // overTime.add(Calendar.DATE, overDay);
  453. // overTime.set(Calendar.MINUTE, 0);
  454. // overTime.set(Calendar.SECOND, 0);
  455. int i = 0, j = 0;
  456. while (i < overDay) {
  457. j++;
  458. overTime.setTime(DateUtil.parseTimeStringToDate(create_time, "yyyy-MM-dd HH:mm:ss"));
  459. overTime.add(Calendar.DATE, j);
  460. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMdd");
  461. String deadline = simpleDateFormat.format(overTime.getTime());
  462. if (!holiday.contains(deadline)) {
  463. i++;
  464. }
  465. }
  466. overTime.set(Calendar.HOUR_OF_DAY, 23);
  467. overTime.set(Calendar.MINUTE, 0);
  468. overTime.set(Calendar.SECOND, 0);
  469. now.setTime(new Date());
  470. now.set(Calendar.MINUTE, 0);
  471. now.set(Calendar.SECOND, 0);
  472. String deadline = getTimeString(overTime.getTime());
  473. String nowDate = getTimeString(new Date());
  474. //得到两个日期相差的小时数
  475. int hours = ((int) (overTime.getTime().getTime() / 1000) - (int) (now.getTime().getTime() / 1000)) / 3600;
  476. if (hours > 24) {
  477. int count = (int) Math.ceil(hours / 24);
  478. List<String> days = getDays(nowDate, deadline, "yyyy-MM-dd HH:mm:ss", "MMdd");
  479. for (String day : days) {
  480. if (holiday.contains(day)) {
  481. count--;
  482. }
  483. }
  484. overTimeStr = "剩余" + count + "个工作日";
  485. } else {
  486. int count = (int) Math.abs(Math.ceil(hours / 24));
  487. List<String> days = getDays(deadline, nowDate, "yyyy-MM-dd HH:mm:ss", "MMdd");
  488. for (String day : days) {
  489. if (holiday.contains(day)) {
  490. count--;
  491. }
  492. }
  493. overTimeStr = "超出" + count + "个工作日";
  494. }
  495. }
  496. return overTimeStr;
  497. }
  498. }
  499. /**
  500. * 获取两个日期之间的所有日期
  501. *
  502. * @param startTime 开始日期
  503. * @param endTime 结束日期
  504. * @return
  505. */
  506. public static List<String> getDays(String startTime, String endTime, String pattern1, String pattern2) {
  507. // 返回的日期集合
  508. List<String> days = new ArrayList<String>();
  509. if (pattern1 == null || pattern1 == "") {
  510. pattern1 = "yyyy-MM-dd";
  511. }
  512. if (pattern2 == null || pattern2 == "") {
  513. pattern2 = "yyyy-MM-dd";
  514. }
  515. DateFormat dateFormat1 = new SimpleDateFormat(pattern1);
  516. DateFormat dateFormat2 = new SimpleDateFormat(pattern2);
  517. try {
  518. Date start = dateFormat1.parse(startTime);
  519. Date end = dateFormat1.parse(endTime);
  520. Calendar tempStart = Calendar.getInstance();
  521. tempStart.setTime(start);
  522. Calendar tempEnd = Calendar.getInstance();
  523. tempEnd.setTime(end);
  524. tempEnd.add(Calendar.DATE, +0);
  525. while (tempStart.before(tempEnd)) {
  526. days.add(dateFormat2.format(tempStart.getTime()));
  527. tempStart.add(Calendar.DAY_OF_YEAR, 1);
  528. }
  529. } catch (ParseException e) {
  530. e.printStackTrace();
  531. }
  532. return days;
  533. }
  534. protected static int absoluteDay(Calendar cal, boolean use1904windowing) {
  535. return 0;
  536. }
  537. }