{"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":"%e0%b9%80%e0%b8%94%e0%b8%b7%e0%b8%ad%e0%b8%99%e0%b8%97%e0%b8%b5%e0%b9%88%e0%b9%81%e0%b8%95%e0%b8%81%e0%b8%95%e0%b9%88%e0%b8%b2%e0%b8%87%e0%b8%81%e0%b8%b1%e0%b8%99","status":"publish","type":"post","link":"https:\/\/chat-messenger.com\/th\/blog\/java\/difference-month","title":{"rendered":"\u0e20\u0e32\u0e29\u0e32 Java: \u0e04\u0e33\u0e19\u0e27\u0e13\u0e04\u0e27\u0e32\u0e21\u0e41\u0e15\u0e01\u0e15\u0e48\u0e32\u0e07\u0e02\u0e2d\u0e07\u0e08\u0e33\u0e19\u0e27\u0e19\u0e40\u0e14\u0e37\u0e2d\u0e19\u0e23\u0e30\u0e2b\u0e27\u0e48\u0e32\u0e07\u0e2a\u0e2d\u0e07\u0e27\u0e31\u0e19\u0e17\u0e35\u0e48"},"content":{"rendered":"<h2 class=\"common_title\"><a name=\"0\">\u0e20\u0e32\u0e29\u0e32 Java: \u0e04\u0e33\u0e19\u0e27\u0e13\u0e04\u0e27\u0e32\u0e21\u0e41\u0e15\u0e01\u0e15\u0e48\u0e32\u0e07\u0e02\u0e2d\u0e07\u0e08\u0e33\u0e19\u0e27\u0e19\u0e40\u0e14\u0e37\u0e2d\u0e19\u0e23\u0e30\u0e2b\u0e27\u0e48\u0e32\u0e07\u0e2a\u0e2d\u0e07\u0e27\u0e31\u0e19\u0e17\u0e35\u0e48<\/a><\/h2>\n<p>\n\u0e43\u0e19\u0e20\u0e32\u0e29\u0e32\u0e08\u0e32\u0e27\u0e32 \u0e21\u0e35\u0e2a\u0e2d\u0e07\u0e2d\u0e22\u0e48\u0e32\u0e07<strong>\u0e04\u0e27\u0e32\u0e21\u0e41\u0e15\u0e01\u0e15\u0e48\u0e32\u0e07\u0e02\u0e2d\u0e07\u0e08\u0e33\u0e19\u0e27\u0e19\u0e40\u0e14\u0e37\u0e2d\u0e19\u0e43\u0e19\u0e27\u0e31\u0e19\u0e17\u0e35\u0e48<\/strong>\u0e19\u0e35\u0e48\u0e04\u0e37\u0e2d\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e42\u0e1b\u0e23\u0e41\u0e01\u0e23\u0e21\u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a\u0e2b\u0e32\u0e04\u0e33\u0e15\u0e2d\u0e1a<br \/>\n\u0e42\u0e1b\u0e23\u0e41\u0e01\u0e23\u0e21\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e19\u0e35\u0e49\u0e23\u0e2d\u0e07\u0e23\u0e31\u0e1a\u0e17\u0e31\u0e49\u0e07\u0e01\u0e23\u0e13\u0e35\u0e17\u0e35\u0e48\u0e27\u0e31\u0e19\u0e17\u0e35\u0e48\u0e19\u0e33\u0e21\u0e32\u0e40\u0e1b\u0e23\u0e35\u0e22\u0e1a\u0e40\u0e17\u0e35\u0e22\u0e1a\u0e2d\u0e22\u0e39\u0e48\u0e43\u0e19\u0e23\u0e39\u0e1b\u0e41\u0e1a\u0e1a\u0e2a\u0e15\u0e23\u0e34\u0e07 (yyyy\/MM\/dd) \u0e41\u0e25\u0e30\u0e23\u0e39\u0e1b\u0e41\u0e1a\u0e1a java.util.Date\n<\/p>\n<p><strong>\u0e04\u0e27\u0e32\u0e21\u0e41\u0e15\u0e01\u0e15\u0e48\u0e32\u0e07\u0e43\u0e19\u0e08\u0e33\u0e19\u0e27\u0e19\u0e40\u0e14\u0e37\u0e2d\u0e19<\/strong>\u0e27\u0e34\u0e18\u0e35\u0e01\u0e32\u0e23\u0e04\u0e33\u0e19\u0e27\u0e13\u0e2b\u0e32\u0e04\u0e48\u0e32\u0e19\u0e35\u0e49\u0e21\u0e35\u0e14\u0e31\u0e07\u0e15\u0e48\u0e2d\u0e44\u0e1b\u0e19\u0e35\u0e49:<\/p>\n<ol>\n<li>\u0e02\u0e31\u0e49\u0e19\u0e41\u0e23\u0e01 \u0e43\u0e2b\u0e49\u0e23\u0e27\u0e21\u0e27\u0e31\u0e19\u0e17\u0e35\u0e48\u0e17\u0e31\u0e49\u0e07\u0e2a\u0e2d\u0e07\u0e40\u0e02\u0e49\u0e32\u0e40\u0e1b\u0e47\u0e19\u0e27\u0e31\u0e19\u0e40\u0e14\u0e35\u0e22\u0e27\u0e01\u0e31\u0e19<br \/>\n    * \u0e43\u0e0a\u0e49 Calendar.set(Calendar.DATE, 1)<\/li>\n<li>\u0e15\u0e48\u0e2d\u0e44\u0e1b \u0e40\u0e23\u0e32\u0e08\u0e30\u0e40\u0e1b\u0e23\u0e35\u0e22\u0e1a\u0e40\u0e17\u0e35\u0e22\u0e1a\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e17\u0e31\u0e49\u0e07\u0e2a\u0e2d\u0e07\u0e0a\u0e38\u0e14\u0e0b\u0e49\u0e33\u0e46 \u0e17\u0e38\u0e01\u0e40\u0e14\u0e37\u0e2d\u0e19<br \/>\n    * \u0e43\u0e0a\u0e49 Calendar.add(Calendar.MONTH, 1 \u0e2b\u0e23\u0e37\u0e2d -1) \u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e40\u0e1e\u0e34\u0e48\u0e21\u0e2b\u0e23\u0e37\u0e2d\u0e25\u0e1a\u0e40\u0e14\u0e37\u0e2d\u0e19\u0e17\u0e35\u0e25\u0e30\u0e2b\u0e19\u0e36\u0e48\u0e07\u0e40\u0e14\u0e37\u0e2d\u0e19<\/li>\n<li>\u0e19\u0e35\u0e48\u0e40\u0e1b\u0e47\u0e19\u0e01\u0e32\u0e23\u0e19\u0e31\u0e1a\u0e08\u0e33\u0e19\u0e27\u0e19\u0e04\u0e23\u0e31\u0e49\u0e07\u0e17\u0e35\u0e48\u0e17\u0e33\u0e01\u0e32\u0e23\u0e40\u0e1b\u0e23\u0e35\u0e22\u0e1a\u0e40\u0e17\u0e35\u0e22\u0e1a\u0e0b\u0e49\u0e33<\/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\">\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e41\u0e2b\u0e25\u0e48\u0e07\u0e17\u0e35\u0e48\u0e21\u0e32<\/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\">\u0e01\u0e32\u0e23\u0e1b\u0e23\u0e30\u0e2b\u0e32\u0e23\u0e0a\u0e35\u0e27\u0e34\u0e15<\/a><\/h2>\n<p>\u25c6\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07<\/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;\u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c 1 = &quot;+ret); ret = differenceMonth(&quot;2008\/7\/1&quot;,&quot;2008\/6\/3&quot;); System.out.println(&quot;\u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c 2 = &quot;+ret); ret = differenceMonth(&quot;2008\/12\/20&quot;,&quot;2008\/6\/1&quot;); System.out.println(&quot;\u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c 3 = &quot;+ret); ret = differenceMonth(&quot;2010\/6\/20&quot;,&quot;2008\/6\/1&quot;); System.out.println(&quot;\u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c 4 = &quot;+ret); ret = differenceMonth(&quot;2008\/6\/1&quot;,&quot;2008\/7\/1&quot;); System.out.println(&quot;\u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e17\u0e35\u0e48 5 = &quot;+ret); ret = differenceMonth(&quot;2008\/7\/1&quot;,&quot;2009\/7\/1&quot;); System.out.println(&quot;\u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e17\u0e35\u0e48 6 = &quot;+ret); }\r\n<\/pre>\n<p>\u25c6\u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e01\u0e32\u0e23\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23<\/p>\n<pre class=\"console\">\u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e17\u0e35\u0e48 1 = 0 \u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e17\u0e35\u0e48 2 = 1 \u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e17\u0e35\u0e48 3 = 6 \u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e17\u0e35\u0e48 4 = 24 \u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e17\u0e35\u0e48 5 = -1 \u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e17\u0e35\u0e48 6 = -12\r\n<\/pre>\n<p>\n\u0e42\u0e1b\u0e23\u0e41\u0e01\u0e23\u0e21\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e19\u0e35\u0e49\u0e43\u0e0a\u0e49\u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a\u0e41\u0e2d\u0e1b\u0e1e\u0e25\u0e34\u0e40\u0e04\u0e0a\u0e31\u0e19 Chat&amp;Messenger<a href=\"\/th\/%e0%b8%84%e0%b8%b9%e0%b9%88%e0%b8%a1%e0%b8%b7%e0%b8%ad\/%e0%b8%9b%e0%b8%8f%e0%b8%b4%e0%b8%97%e0%b8%b4%e0%b8%99%e0%b8%81%e0%b8%b3%e0%b8%ab%e0%b8%99%e0%b8%94%e0%b8%81%e0%b8%b2%e0%b8%a3\/%e0%b8%9b%e0%b8%8f%e0%b8%b4%e0%b8%97%e0%b8%b4%e0%b8%99\/\" title=\"\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e19\u0e01\u0e32\u0e23\u0e08\u0e31\u0e14\u0e01\u0e32\u0e23\u0e1b\u0e0f\u0e34\u0e17\u0e34\u0e19\u0e41\u0e25\u0e30\u0e15\u0e32\u0e23\u0e32\u0e07\u0e40\u0e27\u0e25\u0e32\">\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e19\u0e01\u0e32\u0e23\u0e08\u0e31\u0e14\u0e01\u0e32\u0e23\u0e1b\u0e0f\u0e34\u0e17\u0e34\u0e19\u0e41\u0e25\u0e30\u0e15\u0e32\u0e23\u0e32\u0e07\u0e40\u0e27\u0e25\u0e32<\/a>\u0e08\u0e23\u0e34\u0e07\u0e46 \u0e41\u0e25\u0e49\u0e27\u0e09\u0e31\u0e19\u0e01\u0e33\u0e25\u0e31\u0e07\u0e43\u0e0a\u0e49\u0e21\u0e31\u0e19\u0e43\u0e19 [\u0e1a\u0e23\u0e34\u0e1a\u0e17\u0e19\u0e35\u0e49]<\/p>","protected":false},"excerpt":{"rendered":"<p>Java 2\u3064\u306e\u65e5\u4ed8\u306e\u6708\u6570\u306e\u5dee\u3092\u6c42\u3081\u308b Java \u3067\u30012\u3064\u306e\u65e5\u4ed8\u306e\u6708\u6570\u306e\u5dee\u3092\u6c42\u3081\u308b\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d39\u4ecb\u3057\u307e [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[19],"tags":[],"class_list":["post-951","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/chat-messenger.com\/th\/wp-json\/wp\/v2\/posts\/951","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chat-messenger.com\/th\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chat-messenger.com\/th\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/th\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/th\/wp-json\/wp\/v2\/comments?post=951"}],"version-history":[{"count":4,"href":"https:\/\/chat-messenger.com\/th\/wp-json\/wp\/v2\/posts\/951\/revisions"}],"predecessor-version":[{"id":1878,"href":"https:\/\/chat-messenger.com\/th\/wp-json\/wp\/v2\/posts\/951\/revisions\/1878"}],"wp:attachment":[{"href":"https:\/\/chat-messenger.com\/th\/wp-json\/wp\/v2\/media?parent=951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chat-messenger.com\/th\/wp-json\/wp\/v2\/categories?post=951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chat-messenger.com\/th\/wp-json\/wp\/v2\/tags?post=951"}],"curies":[{"name":"\u0e14\u0e31\u0e1a\u0e40\u0e1a\u0e34\u0e25\u0e22\u0e39\u0e1e\u0e35","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}