{"id":89,"date":"2023-02-14T21:43:20","date_gmt":"2023-02-14T13:43:20","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=89"},"modified":"2023-02-14T21:43:46","modified_gmt":"2023-02-14T13:43:46","slug":"localdatetime-increase-decrease","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/14\/localdatetime-increase-decrease\/","title":{"rendered":"LocalDateTime\u7684\u589e\u52a0\u548c\u51cf\u5c11"},"content":{"rendered":"<h3>\u683c\u5f0f\u5316\u8f93\u51fa<\/h3>\n<pre><code class=\"language-java\">DateTimeFormatter formatter = DateTimeFormatter.ofPattern(&quot;yyyy-MM-dd HH:mm:ss&quot;);\nLocalDateTime localDateTime = LocalDateTime.now();\n\/\/\u52a030\u5929\nLocalDateTime dueDateTime = localDateTime.plus(30, ChronoUnit.DAYS);\nSystem.out.println(dueDateTime.format(formatter));<\/code><\/pre>\n<h3>\u8ba1\u7b97\u4e24\u4e2aLocalDateTime\u4e4b\u95f4\u7684\u76f8\u5dee\u7684\u5929\u6570<\/h3>\n<pre><code class=\"language-java\">\/\/\u6307\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u65f6\u95f4\nString startTime = &quot;2019-07-01 00:00:01&quot;;\nDateTimeFormatter formatter = DateTimeFormatter.ofPattern(&quot;yyyy-MM-dd HH:mm:ss&quot;);\nLocalDateTime dateTime = LocalDateTime.parse(startTime, formatter);\n\/\/\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\nLocalDateTime now = LocalDateTime.now();\nint days = (int) Duration.between(dateTime, now).toDays();\nSystem.out.println(days);<\/code><\/pre>\n<h3>LocalDate\u7684\u51cf\u5c11\u6307\u5b9a\u7684\u5929\u6570\u3001\u5e74\u6570\u7b49<\/h3>\n<pre><code class=\"language-java\">LocalDate localDate = LocalDate.now();\n\/\/\u8ba1\u7b97\u53bb\u5e74\nLocalDate previousYear = localDate.minus(1, ChronoUnit.YEARS);\n\/\/\u51cf30\u5929\nLocalDate previousDay = localDate.minus(30, ChronoUnit.DAYS);\n\/\/\u51cf\u5c116\u5929\nLocalDate startTime = localDate.minusDays(6);<\/code><\/pre>\n<h3>LocalDate\u8ba1\u7b97\u4e0a\u5468\u65e5\u7684\u65e5\u671f<\/h3>\n<pre><code class=\"language-java\">LocalDate localDate = LocalDate.now();  \/\/\u5f53\u524d\u65e5\u671f\nint week = localDate.getDayOfWeek().getValue();  \/\/\u8ba1\u7b97\u4eca\u5929\u662f\u661f\u671f\u51e0\nLocalDate endTime = localDate.minusDays(week);  \/\/\u8ba1\u7b97\u4e0a\u5468\u65e5\u7684\u65e5\u671f<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u683c\u5f0f\u5316\u8f93\u51fa DateTimeFormatter formatter = DateTimeFormatter.o [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-89","post","type-post","status-publish","format-standard","hentry","category-java-basic"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}