{"id":963,"date":"2018-09-17T18:52:48","date_gmt":"2018-09-17T09:52:48","guid":{"rendered":"https:\/\/chat-messenger.com\/?p=963"},"modified":"2018-12-23T01:52:16","modified_gmt":"2018-12-22T16:52:16","slug":"calendar-getactualmaximum","status":"publish","type":"post","link":"https:\/\/chat-messenger.com\/zh\/\u535a\u5ba2\/java\/calendar-getactualmaximum","title":{"rendered":"Java \u83b7\u53d6\u6708\u672b\u65e5\u671f"},"content":{"rendered":"<h2 class=\"common_title\"><a name=\"0\"><strong>Java <\/strong><strong>\u6708\u5e95\u65e5\u671f<\/strong>\u83b7\u53d6 <strong>Calendar.getActualMaximum().<\/strong><\/a><\/h2>\n<p>\n<strong>Java<\/strong>\u4e2d\u6307\u5b9a\u7684\u65e5\u671f<strong>\u6708\u5e95\u65e5\u671f<\/strong>\u6837\u672c\u65b9\u6848\uff0c\u4ee5\u83b7\u5f97<br \/>\n<strong>java.util.Calendar.<\/strong>\u73ed\u7ea7<strong>getActualMaximum(Calendar.DATE)<\/strong>\u5728<strong>\u6708\u5e95\u65e5\u671f<\/strong>\u4ee5\u83b7\u53d6\u4ee5\u4e0b\u4fe1\u606f\u3002\n<\/p>\n<h2 class=\"common_title\"><a name=\"1\">\u793a\u4f8b\u7a0b\u5e8f<\/a><\/h2>\n<pre class=\"sample_src\">\/**\r\n * \u7ed9\u5b9a\u7684\u65e5\u671f\u5b57\u7b26\u4e32\uff08yyyy\/MM\/dd \u6216 yyyy-MM-dd\uff09\r\n * \u8fd4\u56de\u6708\u672b\u65e5\u671f\u3002\r\n *\r\n * @param strDate \u76ee\u6807\u65e5\u671f\u5b57\u7b26\u4e32\u3002\r\n * \u8fd4\u56de\u6708\u672b\u65e5\u671f\u3002\r\n *\/\r\npublic static int getLastDay(String strDate) {\r\n    if (strDate == null || strDate.length() \uff01= 10) {\r\n        \u629b\u51fa\u65b0\u7684 IllegalArgumentException(\r\n                \"\u53c2\u6570\u5b57\u7b26\u4e32 [\"+ strDate +\"]\" +\r\n                \"\"\u4e0d\u5408\u6cd5\u3002\");\r\n    }\r\n    int yyyy = Integer.parseInt(strDate.substring(0,4));.\r\n    int MM = Integer.parseInt(strDate.substring(5,7)); }.\r\n    int dd = Integer.parseInt(strDate.substring(8,10)); }\uff1b\r\n    Calendar cal = Calendar.getInstance()\uff1b\r\n    cal.set(yyyyy,MM-1,dd)\uff1b\r\n    int last = cal.getActualMaximum(Calendar.DATE)\uff1b\r\n    return last; }\r\n}\r\n<\/pre>\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\">\u6267\u884c\u7ed3\u679c<\/a><\/h2>\n<p>\u6267\u884c\u793a\u4f8b<\/p>\n<pre class=\"sample_src\">public static void main(String[] args) {\r\n    System.out.println(getLastDay(\"2007\/01\/01\"))\uff1b\r\n    System.out.println(getLastDay(\"2007\/02\/01\"))\uff1b\r\n    System.out.println(getLastDay(\"2008\/02\/01\"))\uff1b\r\n}\r\n<\/pre>\n<p>\u8f93\u51fa\u7ed3\u679c<\/p>\n<pre class=\"console\">31\r\n28\r\n29\r\n<\/pre>\n<p>*\u56e0\u4e3a 2008 \u5e74\u662f\u95f0\u5e74\uff0c\u6240\u4ee5 2 \u6708\u7684\u7ed3\u675f\u65e5\u671f\u662f 29 \u65e5\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>Java \u83b7\u53d6\u6708\u4efd\u7684\u7ed3\u675f\u65e5\u671f Calendar.getActualMaximum() Java \u4e2d\u6307\u5b9a\u7684\u65e5\u671f [...]<\/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\/zh\/wp-json\/wp\/v2\/posts\/963"}],"collection":[{"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/comments?post=963"}],"version-history":[{"count":4,"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/posts\/963\/revisions"}],"predecessor-version":[{"id":1874,"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/posts\/963\/revisions\/1874"}],"wp:attachment":[{"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/media?parent=963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/categories?post=963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chat-messenger.com\/zh\/wp-json\/wp\/v2\/tags?post=963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}