{"id":948,"date":"2018-09-17T18:43:54","date_gmt":"2018-09-17T09:43:54","guid":{"rendered":"https:\/\/chat-messenger.com\/?p=948"},"modified":"2019-07-01T00:27:48","modified_gmt":"2019-06-30T15:27:48","slug":"date-difference","status":"publish","type":"post","link":"https:\/\/chat-messenger.com\/ko\/blog\/java\/date-difference","title":{"rendered":"Java \ub450 \ub0a0\uc9dc\uc758 \ucc28\uc774\ub97c \ucc3e\uc2b5\ub2c8\ub2e4."},"content":{"rendered":"<h2 class=\"common_title\"><a name=\"0\">Java \ub450 \ub0a0\uc9dc\uc758 \ucc28\uc774\ub97c \ucc3e\uc2b5\ub2c8\ub2e4.<\/a><\/h2>\n<p>\nJava\uc5d0\uc11c \ub450 \uac00\uc9c0<strong>\ub0a0\uc9dc \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>\ub0a0\uc9dc \ucc28\uc774<\/strong>\ub97c \uad6c\ud558\ub294 \uacc4\uc0b0 \ubc29\ubc95\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<ol>\n<li>\ucc98\uc74c \ub450 \ub0a0\uc9dc\ub97c long \uac12\uc73c\ub85c \ubcc0\ud658\ud569\ub2c8\ub2e4.<br \/>\n    \u203b\uc774 long \uce58\ub294 1970 \ub144 1 \uc6d4 1 \uc77c 00:00:00 GMT \ub85c\ubd80\ud130\uc758 \uacbd\uacfc \ubc00\ub9ac \uc138\ucee8\ub4dc\uc218\uac00 \ub429\ub2c8\ub2e4.<\/li>\n<li>\uadf8\ub7f0 \ub2e4\uc74c \uadf8 \ucc28\uc774\ub97c \uad6c\ud569\ub2c8\ub2e4.<\/li>\n<li>\uc704 \uacc4\uc0b0\uc5d0\uc11c \ub098\uc628 \uc218\ub7c9\uc744 \ud558\ub8e8\uc758 \uc2dc\uac04\uc73c\ub85c \ub098\ub204\uc5b4 \ub0a0\uc9dc \ucc28\uc774\ub97c \uad6c\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br \/>\n    \u203b1\uc77c(24\uc2dc\uac04)\uc740 86,400,000\ubc00\ub9ac\ucd08\uc785\ub2c8\ub2e4.<\/li>\n<\/ol>\n<h2 class=\"common_title\"><a name=\"1\">\uc0d8\ud50c \uc18c\uc2a4<\/a><\/h2>\n<p><textarea readonly=\"readonly\" style=\"font-size: 13px;height: 600px;\" class=\"src\" onclick=\"this.focus();this.select()\">\/**<br \/>\n * 2\u3064\u306e\u65e5\u4ed8\u306e\u5dee\u3092\u6c42\u3081\u307e\u3059\u3002<br \/>\n * \u65e5\u4ed8\u6587\u5b57\u5217 strDate1 &#8211; strDate2 \u304c\u4f55\u65e5\u304b\u3092\u8fd4\u3057\u307e\u3059\u3002<br \/>\n *<br \/>\n * @param strDate1    \u65e5\u4ed8\u6587\u5b57\u5217 yyyy\/MM\/dd<br \/>\n * @param strDate2    \u65e5\u4ed8\u6587\u5b57\u5217 yyyy\/MM\/dd<br \/>\n * @return    2\u3064\u306e\u65e5\u4ed8\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 differenceDays(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 differenceDays(date1,date2);<br \/>\n}<br \/>\n\/**<br \/>\n * 2\u3064\u306e\u65e5\u4ed8\u306e\u5dee\u3092\u6c42\u3081\u307e\u3059\u3002<br \/>\n * java.util.Date \u578b\u306e\u65e5\u4ed8 date1 &#8211; date2 \u304c\u4f55\u65e5\u304b\u3092\u8fd4\u3057\u307e\u3059\u3002<br \/>\n *<br \/>\n * \u8a08\u7b97\u65b9\u6cd5\u306f\u4ee5\u4e0b\u3068\u306a\u308a\u307e\u3059\u3002<br \/>\n * 1.\u6700\u521d\u306b2\u3064\u306e\u65e5\u4ed8\u3092 long \u5024\u306b\u5909\u63db\u3057\u307e\u3059\u3002<br \/>\n * \u3000\u203b\u3053\u306e long \u5024\u306f 1970 \u5e74 1 \u6708 1 \u65e5 00:00:00 GMT \u304b\u3089\u306e<br \/>\n * \u3000\u7d4c\u904e\u30df\u30ea\u79d2\u6570\u3068\u306a\u308a\u307e\u3059\u3002<br \/>\n * 2.\u6b21\u306b\u305d\u306e\u5dee\u3092\u6c42\u3081\u307e\u3059\u3002<br \/>\n * 3.\u4e0a\u8a18\u306e\u8a08\u7b97\u3067\u51fa\u305f\u6570\u91cf\u3092 1 \u65e5\u306e\u6642\u9593\u3067\u5272\u308b\u3053\u3068\u3067<br \/>\n * \u3000\u65e5\u4ed8\u306e\u5dee\u3092\u6c42\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n * \u3000\u203b1 \u65e5 ( 24 \u6642\u9593) \u306f\u300186,400,000 \u30df\u30ea\u79d2\u3067\u3059\u3002<br \/>\n *<br \/>\n * @param date1    \u65e5\u4ed8 java.util.Date<br \/>\n * @param date2    \u65e5\u4ed8 java.util.Date<br \/>\n * @return    2\u3064\u306e\u65e5\u4ed8\u306e\u5dee<br \/>\n *\/<br \/>\npublic static int differenceDays(Date date1,Date date2) {<br \/>\n    long datetime1 = date1.getTime();<br \/>\n    long datetime2 = date2.getTime();<br \/>\n    long one_date_time = 1000 * 60 * 60 * 24;<br \/>\n    long diffDays = (datetime1 &#8211; datetime2) \/ one_date_time;<br \/>\n    return (int)diffDays;<br \/>\n}<br \/>\n<\/textarea><\/p>\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=\"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 = differenceDays(&quot;2008\/6\/2&quot;,&quot;2008\/6\/1&quot;); System.out.println(&quot;\uacb0\uacfc 1 = &quot;+ret); ret = differenceDays(&quot;2008\/6\/1&quot;,&quot;2008\/6\/3&quot;); System.out.println(&quot;\uacb0\uacfc 2 = &quot;+ret); \/\/ 5\uc6d4\uc758 \uc77c\uc218\ub294 31\uc77c ret = differenceDays(&quot;2008\/ 6\/1&quot;,&quot;2008\/5\/1&quot;); System.out.println(&quot;\uacb0\uacfc 3 = &quot;+ret); \/\/ 6\uc6d4\uc758 \uc77c\uc218\ub294 30\uc77c ret = differenceDays(&quot;2008\/7\/1&quot;, &quot;2008\/6\/1&quot;); System.out.println(&quot;\uacb0\uacfc 4 = &quot;+ret); \/\/ 2008\ub144\uc740 \uc724\ub144 \ub54c\ubb38\uc5d0 2\uc6d4\uc758 \uc6d4\ub9d0 \ub0a0\uc9dc\ub294 29\uc77c ret = differenceDays(&quot; &quot;,&quot;2008\/2\/28&quot;); System.out.println(&quot;\uacb0\uacfc 5 = &quot;+ret); }\r\n<\/pre>\n<p>\u25c6\uc2e4\ud589 \uacb0\uacfc<\/p>\n<pre class=\"console\">\uacb0\uacfc 1 = 1 \uacb0\uacfc 2 = -2 \uacb0\uacfc 3 = 31 \uacb0\uacfc 4 = 30 \uacb0\uacfc 5 = 2\r\n<\/pre>\n<p>\n\ub450 \ub0a0\uc9dc\uc758 \ucc28\uc774\ub97c \ucc3e\ub294 \ubc29\ubc95\uc740 \ube44\uad50\uc801 \uac04\ub2e8\ud558\uc9c0\ub9cc \uc6d4 \uc218\uc758 \ucc28\uc774\ub97c \ucc3e\ub294 \uacbd\uc6b0\uc5d0\ub294 \uc57d\uac04\uc758 \uc5b4\ub824\uc6c0\uc774 \uc788\uc2b5\ub2c8\ub2e4. \ucc38\uace0\uae4c\uc9c0 \uc774\ud558 \ubd10 \uc8fc\uc138\uc694.<br \/>\n&quot;<a href=\"https:\/\/chat-messenger.com\/ko\/blog\/java\/difference-month\/\" title=\"Java \ub450 \ub0a0\uc9dc\uc758 \uc6d4 \uc218 \ucc28\uc774\ub97c \ucc3e\uc2b5\ub2c8\ub2e4.\">Java \ub450 \ub0a0\uc9dc\uc758 \uc6d4 \uc218 \ucc28\uc774\ub97c \ucc3e\uc2b5\ub2c8\ub2e4.<\/a>&quot;<\/p>\n<p>\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 2\uac1c\uc758 \uc77c\uc790\uc758 \ucc28\uc774\ub97c \uad6c\ud558\ub294 Java\ub85c, 2\uac1c\uc758 \uc77c\uc790\uc758 \ucc28\ub97c \uad6c\ud558\ub294 \uc0d8\ud50c \ud504\ub85c\uadf8\ub7a8\uc744 \uc18c\uac1c\ud569\ub2c8\ub2e4. \uc120 [\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\/948"}],"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=948"}],"version-history":[{"count":8,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/posts\/948\/revisions"}],"predecessor-version":[{"id":3655,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/posts\/948\/revisions\/3655"}],"wp:attachment":[{"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/media?parent=948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/categories?post=948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/tags?post=948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}