TimeExchange.java 21 KB

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