摘要:歡迎關(guān)注我的項(xiàng)目,這篇博文只是完善時(shí)間工具類的測試過程。
歡迎關(guān)注我的項(xiàng)目:https://github.com/duanluan/ZUtil,這篇博文只是完善時(shí)間工具類的測試過程。
代碼:
@DisplayName("時(shí)間工具類測試")public class DateUtilsTest { @DisplayName("探尋 ChronoField") @Test void testChronoField() { String indent = "/t/t/t/t/t/t/t/t/t/t/t/t/t"; LocalDateTime now = LocalDateTime.now(); // 時(shí)代:公元前,相當(dāng)于當(dāng)前時(shí)間的負(fù)數(shù) System.out.println(now.with(ChronoField.ERA, 0) + indent.replaceFirst("/t", "") + "時(shí)代:公元前"); // 時(shí)代:公元,即當(dāng)前時(shí)間 System.out.println(now.with(ChronoField.ERA, 1) + indent + "時(shí)代:公元"); // 公元前所屬年:以當(dāng)前時(shí)間為基礎(chǔ),年修改為公元前 2 年,結(jié)果 -0001-10-01T02:30:32.723 加上當(dāng)前時(shí)間的月份往后 10-01T02:30:32.723 為 2 年 System.out.println(now.with(ChronoField.ERA, 0).with(ChronoField.YEAR_OF_ERA, 2) + indent.replaceFirst("/t", "") + "公元前所屬年"); // 公元后所屬年:以當(dāng)前年月為基礎(chǔ),年修改為 2 年 System.out.println(now.with(ChronoField.ERA, 1).with(ChronoField.YEAR_OF_ERA, 2) + indent + "公元后所屬年"); // 年 System.out.println(now.with(ChronoField.YEAR, 2020) + indent + "年"); // 預(yù)期月,從 0 年開始計(jì)算月(從 0 開始),2021 年 10 月的值為 2021 * 12 + 10 - 1 System.out.println(now.with(ChronoField.PROLEPTIC_MONTH, 0) + indent + "預(yù)期月"); // 年的月 System.out.println(now.with(ChronoField.MONTH_OF_YEAR, 9) + indent + "年的月"); // 年的對(duì)齊周:年的第一天為第一周的第一天 System.out.println(now.with(ChronoField.ALIGNED_WEEK_OF_YEAR, 2) + indent + "年的對(duì)齊周"); // 月的對(duì)齊周:月的第一天為此月第一周的第一天 System.out.println(now.with(ChronoField.ALIGNED_WEEK_OF_MONTH, 2) + indent + "月的對(duì)齊周"); // 年的對(duì)齊周的天 System.out.println(now.with(ChronoField.ALIGNED_WEEK_OF_YEAR, 2).with(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR, 5) + indent + "年的對(duì)齊周的天"); // 月的對(duì)齊周的天 System.out.println(now.with(ChronoField.ALIGNED_WEEK_OF_MONTH, 2).with(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, 5) + indent + "月的對(duì)齊周的天"); // 年的天 System.out.println(now.with(ChronoField.DAY_OF_YEAR, 1) + indent + "年的天"); // 月的天 System.out.println(now.with(ChronoField.DAY_OF_MONTH, 1) + indent + "月的天"); // 周的天 System.out.println(now.with(ChronoField.DAY_OF_WEEK, 1) + indent + "周的天"); // 以 1970-01-01 為 0 開始的天(忽略偏移量和時(shí)區(qū)) System.out.println(now.with(ChronoField.EPOCH_DAY, 1) + indent + "以 1970-01-01 為 0 開始的天(忽略偏移量和時(shí)區(qū))"); // 上午(0-12) System.out.println(now.with(ChronoField.AMPM_OF_DAY, 0) + indent + "上午(0-12)"); // 下午(13-23) System.out.println(now.with(ChronoField.AMPM_OF_DAY, 1) + indent + "下午(13-23)"); // 上午或下午的小時(shí),以當(dāng)前 AMPM 為準(zhǔn),從 0 開始 System.out.println(now.with(ChronoField.HOUR_OF_AMPM, 0) + indent + "上午或下午的小時(shí)"); // 上午的小時(shí) System.out.println(now.with(ChronoField.AMPM_OF_DAY, 0).with(ChronoField.HOUR_OF_AMPM, 0) + indent + "上午的小時(shí)"); // 下午的小時(shí) System.out.println(now.with(ChronoField.AMPM_OF_DAY, 1).with(ChronoField.HOUR_OF_AMPM, 0) + indent + "下午的小時(shí)"); // 12 小時(shí)制,以當(dāng)前 AMPM 為準(zhǔn),從 1 開始 System.out.println(now.with(ChronoField.CLOCK_HOUR_OF_AMPM, 1) + indent + "12 小時(shí)制"); // 上午的 12 小時(shí)制小時(shí) System.out.println(now.with(ChronoField.AMPM_OF_DAY, 0).with(ChronoField.CLOCK_HOUR_OF_AMPM, 1) + indent + "上午的 12 小時(shí)制小時(shí)"); // 下午的 12 小時(shí)制小時(shí) System.out.println(now.with(ChronoField.AMPM_OF_DAY, 1).with(ChronoField.CLOCK_HOUR_OF_AMPM, 1) + indent + "下午的 12 小時(shí)制小時(shí)"); // 天的小時(shí) System.out.println(now.with(ChronoField.HOUR_OF_DAY, 0) + indent + "天的小時(shí)"); // 天的分鐘 System.out.println(now.with(ChronoField.MINUTE_OF_DAY, 1) + indent + "天的分鐘"); // 小時(shí)的分鐘 System.out.println(now.with(ChronoField.MINUTE_OF_HOUR, 1) + indent + "小時(shí)的分鐘"); // 天的秒 System.out.println(now.with(ChronoField.SECOND_OF_DAY, 1) + indent + "天的秒"); // 分鐘的秒 System.out.println(now.with(ChronoField.SECOND_OF_MINUTE, 1) + indent + "分鐘的秒"); // 以 1970-01-01T00:00Z (ISO) 為 0 開始的秒,必須和時(shí)區(qū)結(jié)合使用(+時(shí)區(qū)小時(shí)) System.out.println(now.atZone(ZoneId.systemDefault()).with(ChronoField.INSTANT_SECONDS, 1) + "/t/t以 1970-01-01T00:00Z (ISO) 為 0 開始的秒,必須和時(shí)區(qū)結(jié)合使用(+時(shí)區(qū)小時(shí))"); // 天的毫秒 System.out.println(now.with(ChronoField.MILLI_OF_DAY, 1) + indent + "天的毫秒"); // 秒的毫秒 System.out.println(now.with(ChronoField.MILLI_OF_SECOND, 1) + indent + "秒的毫秒"); // 天的微秒 System.out.println(now.with(ChronoField.MICRO_OF_DAY, 1) + indent.replaceFirst("/t/t", "") + "天的微秒"); // 秒的微秒 System.out.println(now.with(ChronoField.MICRO_OF_SECOND, 1) + indent.replaceFirst("/t/t", "") + "秒的微秒"); // 天的納秒 System.out.println(now.with(ChronoField.NANO_OF_DAY, 1) + indent.replaceFirst("/t/t/t", "") + "天的納秒"); // 秒的納秒 System.out.println(now.with(ChronoField.NANO_OF_SECOND, 1) + indent.replaceFirst("/t/t/t", "") + "秒的納秒"); }}
運(yùn)行結(jié)果,和 “2020-11-21 16:10:43.532” 這個(gè)時(shí)間對(duì)比著看區(qū)別:
-2020-11-21T16:10:43.532 時(shí)代:公元前2021-11-21T16:10:43.532 時(shí)代:公元-0001-11-21T16:10:43.532 公元前所屬年0002-11-21T16:10:43.532 公元后所屬年2020-11-21T16:10:43.532 年0000-01-21T16:10:43.532 預(yù)期月2021-09-21T16:10:43.532 年的月2021-01-10T16:10:43.532 年的對(duì)齊周2021-11-14T16:10:43.532 月的對(duì)齊周2021-01-12T16:10:43.532 年的對(duì)齊周的天2021-11-12T16:10:43.532 月的對(duì)齊周的天2021-01-01T16:10:43.532 年的天2021-11-01T16:10:43.532 月的天2021-11-15T16:10:43.532 周的天1970-01-02T16:10:43.532 以 1970-01-01 為 0 開始的天(忽略偏移量和時(shí)區(qū))2021-11-21T04:10:43.532 上午(0-12)2021-11-21T16:10:43.532 下午(13-23)2021-11-21T12:10:43.532 上午或下午的小時(shí)2021-11-21T00:10:43.532 上午的小時(shí)2021-11-21T12:10:43.532 下午的小時(shí)2021-11-21T13:10:43.532 12 小時(shí)制2021-11-21T01:10:43.532 上午的 12 小時(shí)制小時(shí)2021-11-21T13:10:43.532 下午的 12 小時(shí)制小時(shí)2021-11-21T00:10:43.532 天的小時(shí)2021-11-21T00:01:43.532 天的分鐘2021-11-21T16:01:43.532 小時(shí)的分鐘2021-11-21T00:00:01.532 天的秒2021-11-21T16:10:01.532 分鐘的秒1970-01-01T08:00:01.532+08:00[Asia/Shanghai] 以 1970-01-01T00:00Z (ISO) 為 0 開始的秒,必須和時(shí)區(qū)結(jié)合使用(+時(shí)區(qū)小時(shí))2021-11-21T00:00:00.001 天的毫秒2021-11-21T16:10:43.001 秒的毫秒2021-11-21T00:00:00.000001 天的微秒2021-11-21T16:10:43.000001 秒的微秒2021-11-21T00:00:00.000000001 天的納秒2021-11-21T16:10:43.000000001 秒的納秒
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/124036.html
摘要:陳楊一表達(dá)式與流二初始化測試數(shù)據(jù)三各種方法一方法方法二方法 package com.java.design.java8; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.Spring...
摘要:接口定義代碼角度的接口定義中的接口是一系列方法的聲明,是一些方法特征的集合,一個(gè)接口只有方法的特征沒有方法的實(shí)現(xiàn),因此這些方法可以在不同的地方被不同的類實(shí)現(xiàn),而這些實(shí)現(xiàn)可以具有不同的行為功能。 接口定義 代碼角度的接口Interface 定義:Java中的接口是一系列方法的聲明,是一些方法特征的集合,一個(gè)接口只有方法的特征沒有方法的實(shí)現(xiàn),因此這些方法可以在不同的地方被不同的類實(shí)現(xiàn),而這...
摘要:探索專為而設(shè)計(jì)的將探討進(jìn)行了何種改進(jìn),以及這些改進(jìn)背后的原因。關(guān)于最友好的文章進(jìn)階前言之前就寫過一篇關(guān)于最友好的文章反響很不錯(cuò),由于那篇文章的定位就是簡單友好,因此盡可能的摒棄復(fù)雜的概念,只抓住關(guān)鍵的東西來講,以保證大家都能看懂。 周月切換日歷 一個(gè)可以進(jìn)行周月切換的日歷,左右滑動(dòng)的切換月份,上下滑動(dòng)可以進(jìn)行周,月不同的視圖切換,可以進(jìn)行事件的標(biāo)記,以及節(jié)假日的顯示,功能豐富 Andr...
閱讀 1818·2021-11-22 09:34
閱讀 3102·2019-08-30 15:55
閱讀 681·2019-08-30 15:53
閱讀 2069·2019-08-30 15:52
閱讀 3010·2019-08-29 18:32
閱讀 2004·2019-08-29 17:15
閱讀 2410·2019-08-29 13:14
閱讀 3567·2019-08-28 18:05