{"id":951,"date":"2018-09-17T18:45:12","date_gmt":"2018-09-17T09:45:12","guid":{"rendered":"https:\/\/chat-messenger.com\/?p=951"},"modified":"2018-12-23T01:52:45","modified_gmt":"2018-12-22T16:52:45","slug":"difference-month","status":"publish","type":"post","link":"https:\/\/chat-messenger.com\/ko\/blog\/java\/difference-month","title":{"rendered":"Java \ub450 \ub0a0\uc9dc\uc758 \uc6d4 \uc218 \ucc28\uc774\ub97c \ucc3e\uc2b5\ub2c8\ub2e4."},"content":{"rendered":"<h2 class=\"common_title\"><a name=\"0\">Java \ub450 \ub0a0\uc9dc\uc758 \uc6d4 \uc218 \ucc28\uc774\ub97c \ucc3e\uc2b5\ub2c8\ub2e4.<\/a><\/h2>\n<p>\nJava\uc5d0\uc11c \ub450 \uac00\uc9c0<strong>\ub0a0\uc9dc\uc758 \uc6d4 \uc218 \ucc28\uc774<\/strong>\ub97c \uc694\uad6c\ud558\ub294 \uc0d8\ud50c \ud504\ub85c\uadf8\ub7a8\uc744 \uc18c\uac1c\ud569\ub2c8\ub2e4.<br \/>\n\uc0d8\ud50c \ud504\ub85c\uadf8\ub7a8\uc5d0\uc11c\ub294 \ube44\uad50 \ub300\uc0c1\uc758 \uc77c\uc790\uac00, \uce90\ub9ad\ud130 \ub77c\uc778 ( yyyy\/MM\/dd )\uc758 \uacbd\uc6b0, java.util.Date \uc758 \uacbd\uc6b0\uc5d0 \ub300\uc751\ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4.\n<\/p>\n<p><strong>\uc6d4\uc218 \ucc28\uc774<\/strong>\ub97c \uad6c\ud558\ub294 \uacc4\uc0b0 \ubc29\ubc95\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<ol>\n<li>\uba3c\uc800 \ub450 \ub0a0\uc9dc\ub97c \ud558\ub8e8\ub85c \ub9cc\ub4ed\ub2c8\ub2e4.<br \/>\n    \u203b Calendar.set(Calendar.DATE, 1) \uc744 \uc774\uc6a9\ud569\ub2c8\ub2e4.<\/li>\n<li>\uadf8\ub7f0 \ub2e4\uc74c \ub450 \ub0a0\uc9dc\ub97c \ud55c \ub2ec \ub2e8\uc704\ub85c \ubc18\ubcf5 \ube44\uad50\ud569\ub2c8\ub2e4.<br \/>\n    \u203b Calendar.add(Calendar.MONTH, 1 \ub610\ub294 -1) \ub97c \uc774\uc6a9\ud574, 1\uac1c\uc6d4\uc529 \uc6d4\uc218\ub97c \uac00\uc0b0\u00b7\uac10\uc0b0\ud574 \uac11\ub2c8\ub2e4.<\/li>\n<li>\ubc18\ubcf5 \ube44\uad50\ud55c \ud69f\uc218\ub97c \uce74\uc6b4\ud2b8\ud569\ub2c8\ub2e4.<\/li>\n<\/ol>\n<p><script type=\"text\/javascript\" src=\"https:\/\/chat-messenger.com\/js\/common.js?dd12sssas2223\" charset=\"UTF-8\"><\/script><br \/>\n<script type=\"text\/javascript\"> writePR(); <\/script><\/p>\n<h2 class=\"common_title\"><a name=\"1\">\uc0d8\ud50c \uc18c\uc2a4<\/a><\/h2>\n<p><textarea readonly=\"readonly\" style=\"font-size: 13px;height: 400px;\" class=\"src\" onclick=\"this.focus();this.select()\">\/**<br \/>\n * 2\u3064\u306e\u65e5\u4ed8\u306e\u6708\u6570\u306e\u5dee\u3092\u6c42\u3081\u307e\u3059\u3002<br \/>\n * \u65e5\u4ed8\u6587\u5b57\u5217 strDate1 &#8211; strDate2 \u304c\u4f55\u30f5\u6708\u304b\u3092\u6574\u6570\u3067\u8fd4\u3057\u307e\u3059\u3002<br \/>\n * \u203b\u7aef\u6570\u306e\u65e5\u6570\u306f\u7121\u8996\u3057\u307e\u3059\u3002<br \/>\n *<br \/>\n * @param strDate1    \u65e5\u4ed8\u6587\u5b57\u52171    yyyy\/MM\/dd<br \/>\n * @param strDate2    \u65e5\u4ed8\u6587\u5b57\u52172    yyyy\/MM\/dd<br \/>\n * @return 2\u3064\u306e\u65e5\u4ed8\u306e\u6708\u6570\u306e\u5dee<br \/>\n * @throws ParseException \u65e5\u4ed8\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u304c\u4e0d\u6b63\u306a\u5834\u5408<br \/>\n *\/<br \/>\npublic static int differenceMonth(String strDate1, String strDate2)<br \/>\n    throws ParseException {<br \/>\n    Date date1 = DateFormat.getDateInstance().parse(strDate1);<br \/>\n    Date date2 = DateFormat.getDateInstance().parse(strDate2);<br \/>\n    return differenceMonth(date1,date2);<br \/>\n}<br \/>\n\/**<br \/>\n * 2\u3064\u306e\u65e5\u4ed8\u306e\u6708\u6570\u306e\u5dee\u3092\u6c42\u3081\u307e\u3059\u3002<br \/>\n * java.util.Date \u578b\u306e\u65e5\u4ed8 date1 &#8211; date2 \u304c\u4f55\u30f5\u6708\u304b\u3092\u6574\u6570\u3067\u8fd4\u3057\u307e\u3059\u3002<br \/>\n * \u203b\u7aef\u6570\u306e\u65e5\u6570\u306f\u7121\u8996\u3057\u307e\u3059\u3002<br \/>\n *<br \/>\n * @param date1    \u65e5\u4ed81 java.util.Date<br \/>\n * @param date2    \u65e5\u4ed82 java.util.Date<br \/>\n * @return 2\u3064\u306e\u65e5\u4ed8\u306e\u6708\u6570\u306e\u5dee<br \/>\n *\/<br \/>\npublic static int differenceMonth(Date date1, Date date2) {<br \/>\n    Calendar cal1 = Calendar.getInstance();<br \/>\n    cal1.setTime(date1);<br \/>\n    cal1.set(Calendar.DATE, 1);<br \/>\n    Calendar cal2 = Calendar.getInstance();<br \/>\n    cal2.setTime(date2);<br \/>\n    cal2.set(Calendar.DATE, 1);<br \/>\n    int count = 0;<br \/>\n    if (cal1.before(cal2)) {<br \/>\n        while (cal1.before(cal2)) {<br \/>\n            cal1.add(Calendar.MONTH, 1);<br \/>\n            count&#8211;;<br \/>\n        }<br \/>\n    } else {<br \/>\n        count&#8211;;<br \/>\n        while (!cal1.before(cal2)) {<br \/>\n            cal1.add(Calendar.MONTH, -1);<br \/>\n            count++;<br \/>\n        }<br \/>\n    }<br \/>\n    return count;<br \/>\n}<br \/>\n<\/textarea><\/p>\n<h2 class=\"common_title\"><a name=\"2\">\uc2e4\ud589<\/a><\/h2>\n<p>\u25c6\uc2e4\ud589\uc608<\/p>\n<pre class=\"sample_src\">public static void main(String[] args) { int ret = differenceMonth(&quot;2008\/6\/30&quot;,&quot;2008\/6\/1&quot;); System.out.println(&quot;\uacb0\uacfc 1 = &quot;+ret); ret = differenceMonth(&quot;2008\/7\/1&quot;,&quot;2008\/6\/3&quot;); System.out.println(&quot;\uacb0\uacfc 2 = &quot;+ret); ret = differenceMonth(&quot;2008\/12\/20&quot;,&quot;2008\/6 \/1&quot;); System.out.println(&quot;\uacb0\uacfc 3 = &quot;+ret); ret = differenceMonth(&quot;2010\/6\/20&quot;,&quot;2008\/6\/1&quot;); System.out.println(&quot;\uacb0\uacfc 4 = &quot;+ret); ret = differenceMonth(&quot;2008\/6\/1&quot;,&quot;2008\/7\/1&quot;); System.out.println(&quot;\uacb0\uacfc 5 = &quot;+ret); ret = differenceMonth(&quot;2008\/7 \/1&quot;,&quot;2009\/7\/1&quot;); System.out.println(&quot;\uacb0\uacfc 6 = &quot;+ret); }\r\n<\/pre>\n<p>\u25c6\uc2e4\ud589 \uacb0\uacfc<\/p>\n<pre class=\"console\">\uacb0\uacfc 1 = 0 \uacb0\uacfc 2 = 1 \uacb0\uacfc 3 = 6 \uacb0\uacfc 4 = 24 \uacb0\uacfc 5 = -1 \uacb0\uacfc 6 = -12\r\n<\/pre>\n<p>\n\uc774 \uc0d8\ud50c \ud504\ub85c\uadf8\ub7a8\uc740 Chat &amp; Messenger\uc758 &quot;<a href=\"https:\/\/chat-messenger.com\/ko\/manual\/schedule_calendar\/calendar\/\" title=\"\uce98\ub9b0\ub354 \uc77c\uc815 \uad00\ub9ac \uae30\ub2a5\">\uce98\ub9b0\ub354 \uc77c\uc815 \uad00\ub9ac \uae30\ub2a5<\/a>&quot;\uc5d0\uc11c \uc2e4\uc81c\ub85c \uc0ac\uc6a9\ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4.<\/p>","protected":false},"excerpt":{"rendered":"<p>Java \ub450 \ub0a0\uc9dc\uc758 \uc6d4 \uc218 \ucc28\uc774\ub97c \ucc3e\ub294 Java\uc5d0\uc11c \ub450 \ub0a0\uc9dc\uc758 \uc6d4 \uc218 \ucc28\uc774\ub97c \ucc3e\ub294 \uc0d8\ud50c \ud504\ub85c\uadf8\ub7a8\uc744 \uc18c\uac1c\ud569\ub2c8\ub2e4 [\u2026]<\/p>","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":""},"categories":[19],"tags":[],"_links":{"self":[{"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/posts\/951"}],"collection":[{"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/comments?post=951"}],"version-history":[{"count":4,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/posts\/951\/revisions"}],"predecessor-version":[{"id":1878,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/posts\/951\/revisions\/1878"}],"wp:attachment":[{"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/media?parent=951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/categories?post=951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/tags?post=951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}