<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ### 新的日期API ``` @Test public void test() { LocalDateTime now = LocalDateTime.now(); System.out.println(now); System.out.println(now.getYear()); System.out.println(now.getMonth()); System.out.println(now.getDayOfMonth()); System.out.println(now.getHour()); System.out.println(now.getMinute()); System.out.println(now.getSecond()); System.out.println(now.getNano()); // 初始化日期 LocalDateTime localDateTime = LocalDateTime.of(2019,12,10,8,30); System.out.println(localDateTime); // 加10天 localDateTime = localDateTime.plusDays(10); System.out.println(localDateTime); // 減少2天 localDateTime = localDateTime.minusYears(2); System.out.println(localDateTime); } @Test public void test2() { // 時間戳 1970年1月1日00:00:00 到某一個時間點的毫秒值 // 默認獲取UTC時區 Instant now = Instant.now(); System.out.println(now); // 時區設置 long epochMilli = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli(); System.out.println(epochMilli); System.out.println(System.currentTimeMillis()); System.out.println(Instant.now().toEpochMilli()); System.out.println(Instant.now().atOffset(ZoneOffset.ofHours(8)).toInstant().toEpochMilli()); } @Test public void test3() throws InterruptedException { // Duration:計算兩個時間之間的間隔 // Period:計算兩個日期之間的間隔 Instant start = Instant.now(); Thread.sleep(800); Instant end = Instant.now(); Duration between = Duration.between(start, end); System.out.println(between); System.out.println(between.toMillis()); // 毫秒 System.out.println(between.getSeconds()); // 秒 System.out.println(between.toNanos()); // 納秒 System.out.println("------------------"); LocalTime start2 = LocalTime.now(); Thread.sleep(800); LocalTime end2 = LocalTime.now(); Duration be = Duration.between(start2, end2); System.out.println(be); System.out.println(be.toMillis()); System.out.println(be.getSeconds()); System.out.println(be.getNano()); } @Test public void test4() throws InterruptedException{ LocalDate end = LocalDate.now(); LocalDate start = LocalDate.of(2018, 5, 25); Period between = Period.between(start, end); System.out.println(between); System.out.println(between.getDays()); // 相隔天數 System.out.println(between.getUnits()); // 單位 System.out.println(between.getMonths()); // 相隔月份 System.out.println(between.getYears()); // 相隔年 System.out.println(between.get(between.getUnits().get(2))); System.out.println(between.getChronology()); } @Test public void test5() { // temperalAdjust 時間校驗器 例如獲取下周日 下一個工作日 LocalDateTime now = LocalDateTime.now(); System.out.println("本月第一天:"+now.withDayOfMonth(1)); // 本月第一天 System.out.println("本年第一天:"+now.withDayOfYear(1)); // 本年第一天 System.out.println("本年第二月:"+now.withMonth(2)); // 本年第二月 System.out.println("下個星期四:"+now.with(TemporalAdjusters.next(DayOfWeek.THURSDAY))); // 下個星期四 System.out.println("上個星期天:"+now.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY))); // 上個星期天 // LocalDateTime plusDays = now.plusDays(1); // 獲取下個工作日 LocalDateTime nextWorkDay = now.with((t)->{ LocalDateTime n = (LocalDateTime)t; DayOfWeek dayOfWeek = n.getDayOfWeek(); if(dayOfWeek.equals(DayOfWeek.FRIDAY)) { n = n.plusDays(3); }else if(dayOfWeek.equals(DayOfWeek.SATURDAY)) { n = n.plusDays(2); }else { n = n.plusDays(1); } return n; }); System.out.println("下個工作日:"+nextWorkDay); } @Test public void test7() { // DateTimeFormatter: 格式化時間/日期 // 自定義格式 LocalDateTime now = LocalDateTime.now(); DateTimeFormatter ofPattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); System.out.println(now.format(ofPattern)); System.out.println(ofPattern.format(now)); DateTimeFormatter isoDateTime = DateTimeFormatter.ISO_DATE_TIME; System.out.println(LocalDateTime.now().format(isoDateTime)); LocalDateTime now2 = LocalDateTime.now(); LocalDateTime parse = LocalDateTime.parse("2020-01-02 15:12:22", ofPattern); System.out.println("當前LocalDateTime對象轉換成String: "+now2.format(ofPattern)); System.out.println("指定的時間轉換成LocalDateTime: "+parse); } // ZoneTime ZoneDate ZoneDateTime @Test public void test8() { LocalDateTime now = LocalDateTime.now(ZoneId.of("America/Chicago")); System.out.println(now); LocalDateTime now2 = LocalDateTime.now(); ZonedDateTime atZone = now2.atZone(ZoneId.of("Asia/Shanghai")); System.out.println(atZone); Set<String> s = ZoneId.getAvailableZoneIds(); s.forEach(System.out::println); } @Test public void test9() { // 5月第一個星期天 LocalDate day = LocalDate.parse("2020-05-01").with(TemporalAdjusters.firstInMonth(DayOfWeek.SUNDAY)); System.out.println(day); // 本月第三個星期五 LocalDate day2 = LocalDate.now().with(TemporalAdjusters.dayOfWeekInMonth(3, DayOfWeek.FRIDAY)); System.out.println(day2); } ``` ***** 原文鏈接:https://blog.csdn.net/qq_29411737/article/details/80835658
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看