{"id":1020,"date":"2004-02-24T12:10:00","date_gmt":"2004-02-24T04:10:00","guid":{"rendered":"http:\/\/www.sunnyblog.net\/blog\/?p=1020"},"modified":"2004-02-24T12:10:00","modified_gmt":"2004-02-24T04:10:00","slug":"%e5%bd%93%e4%bd%a0%e8%a6%81%e7%94%a8%e6%a0%bc%e5%bc%8f%e5%a4%84%e7%90%86%e7%9a%84%e6%97%b6%e5%80%99%ef%bc%8c%e8%af%b7%e6%b3%a8%e6%84%8f%e4%b8%80%e4%b8%8b%e4%bd%a0%e7%9a%84locale","status":"publish","type":"post","link":"https:\/\/www.sunnyblog.net\/blog\/archives\/1020","title":{"rendered":"\u5f53\u4f60\u8981\u7528\u683c\u5f0f\u5904\u7406\u7684\u65f6\u5019\uff0c\u8bf7\u6ce8\u610f\u4e00\u4e0b\u4f60\u7684Locale"},"content":{"rendered":"<p><FONT face=Arial size=2>\u6211\u4eec\u901a\u5e38\u90fd\u5f88\u559c\u6b22\u7528SimpleDateFormat\u6765\u505a\u4e00\u4e9b\u65e5\u671f\u548c\u5b57\u7b26\u4e32\u4e4b\u95f4\u7684\u8f6c\u6362\uff0c\u5c31\u662f\u6240\u8c13\u7684format()\u548cparse()\u4e86\uff0c\u5177\u4f53\u7528\u6cd5\u770b\u7a0b\u5e8f\u6216\u8005\u662fJAVA\u7684API\u6587\u6863\uff0c\u8fd9\u91cc\u4e0d\u7d2f\u8ff0\u4e86\u3002<BR><BR>\u4f46\u662f\u5f80\u5f80\u6211\u4eec\u5fd8\u8bb0\u4e86\uff0cJAVA\u7684\u56fd\u9645\u5316\u8fd9\u4e2a\u8ba9\u4eba\u6b22\u559c\u8ba9\u4eba\u6101\u7684\u4e1c\u897f\u3002<BR><BR>\u4e0b\u9762\u51fa\u73b0\u4e00\u4e2a\u95ee\u9898\uff1a<BR>\u4ee5\u4e0b\u7a0b\u5e8f\u6bb5<BR><\/FONT><PRE>    String dateStr = <FONT color=red>&#8220;17\/Mar\/2003 11:30:51&#8221;<\/FONT>;<BR>    SimpleDateFormat frm = <FONT color=navy><B>new<\/B><\/FONT> SimpleDateFormat(<FONT color=red>&#8220;dd\/MMM\/yyyy HH:mm:ss&#8221;<\/FONT>);<BR>    Date date = frm.parse(dateStr);<BR>&nbsp;<BR>&nbsp;<BR>    SimpleDateFormat frm1 = <FONT color=navy><B>new<\/B><\/FONT> SimpleDateFormat(<FONT color=red>&#8220;yyyy\/MM\/dd HH:mm:ss&#8221;<\/FONT>);<BR>    System.out.println(<FONT color=red>&#8220;reformat : &#8220;<\/FONT> +  frm1.format(date));<BR><\/PRE><BR>\u8fd9\u8fd0\u884c\u65f6\u4f1a\u629b\u51fa\u5f02\u5e38java.text.ParseException: Unparseable date: &#8220;17\/Mar\/2003 11:30:51&#8243;\uff0c\u663e\u7136\u7a0b\u5e8f\u4e0d\u80fdparse\u5230\u201cMar\u201d\u8fd9\u4e2a\u82f1\u6587\u6708\u7684\u7f29\u5199\u3002\u4f46\u662f\u6309\u7167java\u4e0a\u9762\u7684\u6587\u6863\u663e\u793a\uff0c\u4ee5\u4e0a\u7a0b\u5e8f\u662f\u6ca1\u6709\u95ee\u9898\u7684\u3002\u4e00\u4e2a\u5178\u578b\u7684\u8fd0\u884c\u65f6\u5f02\u5e38\u3002\u4e0d\u7528\u8bf4\u8003\u8651\u4e00\u4e0b\u6211\u4eec\u7684\u73af\u5883\u3002<BR><BR>\u5f53\u524d\u7a0b\u5e8f\u7f16\u5199\u7684\u73af\u5883\u662f\u4e2d\u6587winxp\uff0cjdk1.4.2\uff0cIDEA 4.0\uff0c\u5475\u5475\uff0c\u6211\u4eec\u662f\u4e2d\u56fd\u4eba\u5f53\u7136\u90fd\u559c\u6b22\u7528\u4e2d\u6587\u73af\u5883\u5566\u3002\u95ee\u9898\u51fa\u6765\u4e86\u5427\uff1f\u770b\u4e00\u4e0b\u4e00\u6bb5\u4ee3\u7801\uff1a<BR><PRE>            Date date = <FONT color=navy><B>new<\/B><\/FONT> Date();  <BR>            SimpleDateFormat frm1 = <FONT color=navy><B>new<\/B><\/FONT> SimpleDateFormat(<FONT color=red>&#8220;yyyy\/MMM\/dd HH:mm:ss&#8221;<\/FONT>);<BR>            System.out.println(<FONT color=red>&#8220;now : &#8220;<\/FONT> +  frm1.format(date));<BR><\/PRE><BR>\u8f93\u51fa\u7ed3\u679c\u662f\uff1anow : 2004\/\u4e8c\u6708\/24 11:57:00<BR><BR>\u770b\u5230\u4e86\uff0c\u7f3a\u7701\u72b6\u6001\u5e95\u4e0b\uff0c\u6211\u4eec\u7528SimpleDateFormat\u662f\u6309\u7167\u6211\u4eec\u5f53\u524d\u7cfb\u7edf\u7684Locale\uff08\u8bf7\u6055\u6211\u4e00\u76f4\u90fd\u641e\u4e0d\u6e05\u695a\u4ed6\u7684\u4e2d\u6587\u7ffb\u8bd1\uff09\u7684\uff0c\u4e5f\u5c31\u662f\u4e2d\u6587\u7684Locale\uff0c\u4f46\u662f\u6211\u4eec\u8981\u8fdb\u884c\u5206\u6790\u7684\u65e5\u671f\u5b57\u7b26\u4e32\u662f\u82f1\u6587\u7684\uff0c\u5f53\u7136\u5c31\u8ba4\u4e0d\u51fa\u6765\u4e86\u3002<BR>ok\uff0c\u77e5\u9053\u4e86\u4e4b\u540e\uff0c\u6211\u4eec\u4fee\u6539\u4e00\u4e0b\u52a0\u591a\u4e2alocale\u8fdb\u53bb\uff0c\u8ba9SimpleDateFormat\u5728\u6784\u9020\u7684\u65f6\u5019\u6307\u5b9aLocale\uff08Java\u662f\u5f88\u7b28\u7684\uff0c\u6211\u4eec\u4e0d\u8bf4\u4ed6\u600e\u4e48\u77e5\u9053\u5462\uff1f\uff09\u544a\u8bc9\u4ed6\u6211\u4eec\u73b0\u5728\u8981\u5904\u7406\u7684\u662f\u82f1\u6587\u7684\u683c\u5f0f\u4e32<BR><PRE>            Locale locale = Locale.US;<BR>            String dateStr = <FONT color=red>&#8220;17\/Mar\/2003 11:30:51&#8221;<\/FONT>;<BR>            SimpleDateFormat frm = <FONT color=navy><B>new<\/B><\/FONT> SimpleDateFormat(<FONT color=red>&#8220;dd\/MMM\/yyyy HH:mm:ss&#8221;<\/FONT>, locale);<BR>            Date date = frm.parse(dateStr);<BR>&nbsp;<BR>            SimpleDateFormat frm1 = <FONT color=navy><B>new<\/B><\/FONT> SimpleDateFormat(<FONT color=red>&#8220;yyyy\/MM\/dd HH:mm:ss&#8221;<\/FONT>, locale);<BR>            System.out.println(<FONT color=red>&#8220;reformat : &#8220;<\/FONT> +  frm1.format(date));<BR><\/PRE><BR><BR>\u7a0b\u5e8f\u6b63\u5e38\u4e86\u2026\u2026<BR>\u95ee\u9898\u4e3b\u8981\u5c31\u662f\u51fa\u5728\u6211\u4eec\u5728\u4e0d\u540c\u73af\u5883\u5e95\u4e0b\u5bf9\u4e00\u4e9b\u56fd\u9645\u5316\u5904\u7406\u4e0a\u9762\u7684\u4e0d\u5c0f\u5fc3\u6216\u8005\u5bb9\u6613\u5ffd\u7565\u7684\u5730\u65b9\uff0c\u4ec5\u5f53\u4f5c\u6559\u8bad\u4f9b\u5927\u5bb6\u4e00\u7b11\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u901a\u5e38\u90fd\u5f88\u559c\u6b22\u7528SimpleDateFormat\u6765\u505a\u4e00\u4e9b\u65e5\u671f\u548c\u5b57\u7b26\u4e32\u4e4b\u95f4\u7684\u8f6c\u6362\uff0c\u5c31\u662f\u6240\u8c13\u7684format()\u548c &hellip; <a href=\"https:\/\/www.sunnyblog.net\/blog\/archives\/1020\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u5f53\u4f60\u8981\u7528\u683c\u5f0f\u5904\u7406\u7684\u65f6\u5019\uff0c\u8bf7\u6ce8\u610f\u4e00\u4e0b\u4f60\u7684Locale<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[5],"tags":[],"class_list":["post-1020","post","type-post","status-publish","format-standard","hentry","category-develop"],"_links":{"self":[{"href":"https:\/\/www.sunnyblog.net\/blog\/wp-json\/wp\/v2\/posts\/1020","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sunnyblog.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sunnyblog.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sunnyblog.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sunnyblog.net\/blog\/wp-json\/wp\/v2\/comments?post=1020"}],"version-history":[{"count":0,"href":"https:\/\/www.sunnyblog.net\/blog\/wp-json\/wp\/v2\/posts\/1020\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sunnyblog.net\/blog\/wp-json\/wp\/v2\/media?parent=1020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sunnyblog.net\/blog\/wp-json\/wp\/v2\/categories?post=1020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sunnyblog.net\/blog\/wp-json\/wp\/v2\/tags?post=1020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}