{"id":156000,"date":"2020-09-11T21:55:34","date_gmt":"2020-09-11T13:55:34","guid":{"rendered":"http:\/\/4563.org\/?p=156000"},"modified":"2020-09-11T21:55:34","modified_gmt":"2020-09-11T13:55:34","slug":"%e8%af%b7%e6%95%99%e4%b8%80%e4%b8%aa%e5%85%b3%e4%ba%8e-java-%e6%af%94%e8%be%83%e6%97%b6%e9%97%b4%e5%a4%9a%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=156000","title":{"rendered":"\u8bf7\u6559\u4e00\u4e2a\u5173\u4e8e Java \u6bd4\u8f83\u65f6\u95f4\u591a\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bf7\u6559\u4e00\u4e2a\u5173\u4e8e Java \u6bd4\u8f83\u65f6\u95f4\u591a\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wleexi <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>{     \"timers\": [         {             \"dayofWeek\": \"1\",             \"startTimeofDay\": \"20:50\"         },         {             \"dayofWeek\": \"3\",             \"startTimeofDay\": \"20:50\"         },         {             \"dayofWeek\": \"4\",             \"startTimeofDay\": \"23:50\"         }     ] } <\/code><\/pre>\n<p>\u6709\u5982\u4e0a\u7684 JSON \u4e32\u3002dayofWeek \u8868\u793a\u5468\u51e0\uff0cstartTimeofDay \u4ee3\u8868\u4e86\u6307\u5b9a\u7684 dayofWeek \u7684\u65f6\u95f4\u3002 \u9700\u8981\u4ece\u7a0b\u5e8f\u8fd0\u884c\u65f6\u95f4\u7684\u5e74\u6708\u65e5\uff0c\u662f\u5426\u6709\u7b26\u5408\u672a\u6765 24 \u5c0f\u65f6\u7684\u65f6\u95f4\uff0c\u5982\u679c\u6709\u5219\u9009\u51fa\u6ca1\u6709\u5219\u4e0d\u53cd\u6094\u3002 \u8fd9\u6837\u8981\u600e\u4e48\u8ba1\u7b97\u624d\u5408\u7406\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>10<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3311900\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chocovon <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             dayofWeek \u4e3a 1\uff0c\u5f53\u5929\u662f 7\uff0c\u8fd9\u7b97\u672a\u6765 24 \u5c0f\u65f6\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3311901\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wleexi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @chocovon \u6211\u4e0d\u77e5\u9053\u80fd\u4e0d\u80fd\u7406\u89e3\u4f60\u7684\u610f\u601d \uff0c\u73b0\u5728\u662f\u5468\u4e00\uff0c\u9700\u8981\u5728\u4e32\u4e2d\u8d1f\u8d23\u5f53\u524d\u65f6\u95f4\u672a\u6765 24 \u5c0f\u65f6\u5019\u5185\u7684\u8bb0\u5f55\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3311902\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : StopTheWorld <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5468\u4e00\u662f\u672c\u5468\u4e00\u8fd8\u662f\u4e0b\u5468\u4e00\u3002\u611f\u89c9\u7528 LocalDateTime \u633a\u7b80\u5355\u7684\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3311903\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wleexi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @StopTheWorld \u770b\u5f53\u524d\u65f6\u95f4\uff0c\u5982\u679c\u548c\u5f53\u524d\u662f\u5468\u4e00\uff0c\u90a3\u4e48\u5c31\u662f\u4eca\u5929\uff0c\u5982\u679c\u5df2\u7ecf\u8fc7\u4e86\uff0c\u90a3\u4e48\u5c31\u662f\u4e0b\u5468\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3311904\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : nvioue <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u628a\u8fd9\u4e9b\u65f6\u95f4\u6392\u4e2a\u5e8f 2 \u5206\u67e5\u627e \uff1f\uff1f\uff1f \u96be\u70b9\u5728\u54ea\u91cc\uff1f \u8fd8\u662f\u6211\u7406\u89e3\u9519\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3311905\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chendy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             LocalDateTime \u53ef\u505a\uff0c\u7b97\u51fa\u65f6\u95f4\uff0c\u548c\u5f53\u524d\u65f6\u95f4\u53d6 Duration\uff0c\u5224\u65ad\u662f\u4e0d\u662f\u5927\u4e8e\u4e00\u5929<br \/>\u661f\u671f\u51e0\u6ca1\u6709\u73b0\u6210\u65b9\u6cd5\uff0c\u81ea\u5df1\u5224\u65ad\u672c\u5468\u8fd8\u662f\u4e0b\u5468\u53bb plusDays \u5c31\u53ef\u4ee5\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3311906\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wleexi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @chendy \u51fa\u73b0\u8de8\u5e74\uff0c\u8de8\u6708\u7684\u65f6\u5019\u600e\u4e48\u751f\u6210 LocalDateTime \u5462                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3311907\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : aguesuka <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fc7\u5f97 todayOfWeek \u548c tomorrowOfWeek\uff0c\u904d\u5386\uff0c\u5982\u679c\u662f\u4eca\u5929\uff0c\u770b LocalTime \u662f\u5426\u665a\u4e8e\u73b0\u5728\uff0c\u5982\u679c\u662f\u660e\u5929\uff0c\u770b\u65f6\u95f4\u662f\u5426\u65e9\u4e8e\u73b0\u5728                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3311908\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : aguesuka <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \/\/\u81ea\u5df1\u521d\u59cb\u5316\u4ee5\u4e0b\u53c2\u6570<br \/>DayOfWeek today,tomorrow;<br \/>LocalTime now;<\/p>\n<p>list.stream().<br \/>anyMatch(time-&gt; time.dayofWeek.equals(today)&amp;&amp;time.startTimeofDay.isAfter(now)<br \/>||time.dayodWeek.eqauls(tomorrow)&amp;&amp;time.startTimeofDay.isBefor(now))                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3311909\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wleexi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &#8220;`java<\/p>\n<p> List&lt;TimeRecord&gt; timeRecordList = JSONObject.parseObject(recordsDesc, new TypeReference&lt;List&lt;TimeRecord&gt;&gt;() {});<br \/> for (TimeRecord oneRecordTime : timeRecordList) {<br \/> DayOfWeek dayOfWeek = DayOfWeek.of(oneRecordTime.getDayofWeek());<br \/> LocalTime recordTime = oneRecordTime.getStartTimeofDay();<br \/> LocalDateTime recordDateTime = nowDateTime.<br \/> with(TemporalAdjusters.nextOrSame(dayOfWeek)).<br \/> withHour(recordTime.getHour()).<br \/> withMinute(recordTime.getMinute());<\/p>\n<p> long between = ChronoUnit.DAYS.between(nowDateTime,recordDateTime);<br \/> if (between &lt; 1) {<br \/> return recordDateTime;<br \/> }<br \/> }<\/p>\n<p>@Data<br \/>class TimeRecord{<br \/> private Integer dayofWeek;<br \/> private LocalTime startTimeofDay;<br \/>}<\/p>\n<p>&#8220;`<br \/>@aguesuka \u611f\u8c22\u3002\u8fd9\u662f\u6211\u7684\u65b9\u6848\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u6559\u4e00\u4e2a\u5173\u4e8e Java \u6bd4\u8f83\u65f6\u95f4\u591a&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/156000"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=156000"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/156000\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=156000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=156000"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=156000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}