日期类的理解学习

基本介绍

Date(第一代日期类)

/**
 * @author:雷子杰
 * @date:2022/7/21
 */
public class Date01 {
    public static void main(String[] args) throws ParseException {
        //1. 获取当前系统时间
        //2. 这里的 Date 类是在 java.util 包
        //3. 默认输出的日期格式是国外的方式, 因此通常需要对格式进行转换
        Date d1 = new Date(); //获取当前系统时间
        System.out.println("当前日期=" + d1);
        Date d2 = new Date(9234567); //通过指定毫秒数得到时间
        System.out.println("d2=" + d2); //获取某个时间对应的毫秒数

        //1. 创建 SimpleDateFormat 对象,可以指定相应的格式
        //2. 这里的格式使用的字母是规定好,不能乱写
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy 年 MM 月 dd 日 hh:mm:ss E");
        String format = sdf.format(d1); // format:将日期转换成指定格式的字符串
        System.out.println("当前日期=" + format);

        //1. 可以把一个格式化的 String 转成对应的 Date
        //2. 得到 Date 仍然在输出时,还是按照国外的形式,如果希望指定格式输出,需要转换
        //3. 在把 String -> Date , 使用的 sdf 格式需要和你给的 String 的格式一样,否则会抛出转换异常
        String s = "1996 年 01 月 01 日 10:20:30 星期一";
        Date parse = sdf.parse(s);
        System.out.println("parse=" + sdf.format(parse));
    }
}

image-20220721225028108

Calendar(第二代日期类)

/**
 * @author:雷子杰
 * @date:2022/7/21
 */
public class Calendar_ {
    public static void main(String[] args) {
        //1. Calendar 是一个抽象类, 并且构造器是 private
        //2. 可以通过 getInstance() 来获取实例
        //3. 提供大量的方法和字段提供给程序员
        //4. Calendar 没有提供对应的格式化的类,因此需要程序员自己组合来输出(灵活)
        //5. 如果我们需要按照 24 小时进制来获取时间, Calendar.HOUR ==改成=> Calendar.HOUR_OF_DAY
        Calendar c = Calendar.getInstance(); //创建日历类对象//比较简单,自由
        System.out.println("c=" + c);
        //2.获取日历对象的某个日历字段
        System.out.println("年:" + c.get(Calendar.YEAR));
        // 这里为什么要 + 1, 因为 Calendar 返回月时候,是按照 0 开始编号
        System.out.println("月:" + (c.get(Calendar.MONTH) + 1));
        System.out.println("日:" + c.get(Calendar.DAY_OF_MONTH));
        System.out.println("小时:" + c.get(Calendar.HOUR));
        System.out.println("分钟:" + c.get(Calendar.MINUTE));
        System.out.println("秒:" + c.get(Calendar.SECOND));
        //Calender 没有专门的格式化方法,所以需要程序员自己来组合显示
        System.out.println(c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1) + "-" +c.get(Calendar.DAY_OF_MONTH) +
                " " + c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND) );
    }
}

image-20220721225009748

第三代日期类

于JDK8加入

  • LocalDate(日期/年月日):只包含日期,可以获取日期字段

  • LocalTime(时间/时分秒):只包含时间,可以获取时间字段

  • LocalDateTime(日期时间/年月日时分秒):包含日期+时间,可以获取日期和时间字段

/**
 * @author:雷子杰
 * @date:2022/7/21
 */
public class LocalDate_ {
    public static void main(String[] args) {
        //第三代日期
        //1. 使用 now() 返回表示当前日期时间的 对象
        LocalDateTime ldt = LocalDateTime.now(); //LocalDate.now();//LocalTime.now()
        System.out.println(ldt);
        //2. 使用 DateTimeFormatter 对象来进行格式化
        // 创建 DateTimeFormatter 对象
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = dateTimeFormatter.format(ldt);
        System.out.println("格式化的日期=" + format);
        System.out.println("年=" + ldt.getYear());
        System.out.println("月=" + ldt.getMonth());
        System.out.println("月=" + ldt.getMonthValue());
        System.out.println("日=" + ldt.getDayOfMonth());
        System.out.println("时=" + ldt.getHour());
        System.out.println("分=" + ldt.getMinute());
        System.out.println("秒=" + ldt.getSecond());
        LocalDate now = LocalDate.now(); //可以获取年月日
        LocalTime now2 = LocalTime.now();//获取到时分秒
        //提供 plus 和 minus 方法可以对当前时间进行加或者减
        //看看 890 天后,是什么时候 把 年月日-时分秒
        LocalDateTime localDateTime = ldt.plusDays(890);
        System.out.println("890 天后=" + dateTimeFormatter.format(localDateTime));
        //看看在 3456 分钟前是什么时候,把 年月日-时分秒输出
        LocalDateTime localDateTime2 = ldt.minusMinutes(3456);
        System.out.println("3456 分钟前 日期=" + dateTimeFormatter.format(localDateTime2));
    }
}

image-20220721224951813

DateTimeFormatter格式日期类

DateTimeFormatter

//使用 DateTimeFormatter 对象来进行格式化
//创建 DateTimeFormatter 对象
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String format = dateTimeFormatter.format(日期对象);

Instant时间戳

/**
 * @author:雷子杰
 * @date:2022/7/21
 */
public class Instant_ {
    public static void main(String[] args) {
        //1.通过 静态方法 now() 获取表示当前时间戳的对象
        Instant now = Instant.now();
        System.out.println("now:"+now);
        //2. 通过 from 可以把 Instant 转成 Date
        Date date = Date.from(now);
        System.out.println("date:"+date);
        //3. 通过 date 的 toInstant() 可以把 date 转成 Instant 对象
        Instant instant = date.toInstant();

    }
}

image-20220721224913706

全部方法

具体的可以查阅相关api文档

Date(第一代日期类)

Modifier and TypeMethod and Description
booleanafter(Date when) 测试此日期是否在指定日期之后。
booleanbefore(Date when) 测试此日期是否在指定日期之前。
Objectclone() 返回此对象的副本。
intcompareTo(Date anotherDate) 比较两个日期进行订购。
booleanequals(Object obj) 比较两个日期来平等。
static Datefrom(Instant instant)Instant对象获取一个 Date的实例。
intgetDate() 已弃用 截至JDK 1.1版,由Calendar.get(Calendar.DAY_OF_MONTH)
intgetDay() 已弃用 截至JDK 1.1版,由Calendar.get(Calendar.DAY_OF_WEEK)
intgetHours() 已弃用 截至JDK 1.1版,由Calendar.get(Calendar.HOUR_OF_DAY)
intgetMinutes() 已弃用 截至JDK 1.1版,由Calendar.get(Calendar.MINUTE)取代。
intgetMonth() 已弃用 截至JDK 1.1版,由Calendar.get(Calendar.MONTH)取代。
intgetSeconds() 已弃用 截至JDK 1.1版,由Calendar.get(Calendar.SECOND)
longgetTime() 返回自1970年1月1日以来,由此 Date对象表示的00:00:00 GMT的毫秒
intgetTimezoneOffset() 已弃用 自JDK 1.1版起,由-(Calendar.get(Calendar.ZONE_OFFSET) + Calendar.get(Calendar.DST_OFFSET)) / (60 * 1000)取代。
intgetYear() 已弃用 从JDK 1.1版开始,由Calendar.get(Calendar.YEAR) - 1900
inthashCode() 返回此对象的哈希码值。
static longparse(String s) 已弃用 从JDK 1.1版开始,由DateFormat.parse(String s)
voidsetDate(int date) 已弃用 从JDK 1.1版开始,由Calendar.set(Calendar.DAY_OF_MONTH, int date)
voidsetHours(int hours) 已弃用 从JDK 1.1版开始,由Calendar.set(Calendar.HOUR_OF_DAY, int hours)
voidsetMinutes(int minutes) 已弃用 从JDK 1.1版开始,由Calendar.set(Calendar.MINUTE, int minutes)
voidsetMonth(int month) 已弃用 从JDK 1.1版开始,由Calendar.set(Calendar.MONTH, int month)
voidsetSeconds(int seconds) 已弃用 从JDK 1.1版起,由Calendar.set(Calendar.SECOND, int seconds)取代。
voidsetTime(long time) 设置此 Date对象以表示1970年1月1日00:00:00 GMT后的 time毫秒的时间点。
voidsetYear(int year) 已弃用 截至JDK 1.1版,由Calendar.set(Calendar.YEAR, year + 1900)取代。
StringtoGMTString() 已弃用 截至JDK 1.1版,由DateFormat.format(Date date) ,使用GMT TimeZone
InstanttoInstant() 将此 Date对象转换为 Instant
StringtoLocaleString() 已弃用 从JDK 1.1版开始,由DateFormat.format(Date date)替换。
StringtoString() 将此 Date对象转换为 String的形式:
static longUTC(int year, int month, int date, int hrs, int min, int sec) 已弃用 截至JDK 1.1版,由Calendar.set(year + 1900, month, date, hrs, min, sec)GregorianCalendar(year + 1900, month, date, hrs, min, sec) ,使用UTC TimeZone ,其次是Calendar.getTime().getTime()

Calendar(第二代日期类)

Modifier and TypeField and Description
static intALL_STYLES getDisplayNames的样式说明符, 表示所有样式的名称,如“1月”和“1月”。
static intAM AM_PM字段的值表示从午夜到中午之前的一天中的一段时间。
static intAM_PM 对于现场数 getset指示是否 HOUR是前或中午之后。
static intAPRIL MONTH字段的价值 指示了格里高利和朱利安日历中的第四个月。
protected booleanareFieldsSet 如果 fields[]与当前设置的时间同步,则为真。
static intAUGUST MONTH领域的价值 指示了公历和朱利安日历中的第八个月。
static intDATE getset字段编号表示该月的日期。
static intDAY_OF_MONTH get字段编号和 set本月的日期。
static intDAY_OF_WEEK get字段编号和 set表示一周中的日期。
static intDAY_OF_WEEK_IN_MONTH get字段编号和 set当月的 set几的序号。
static intDAY_OF_YEAR getset字段编号, set本年度的日数。
static intDECEMBER MONTH字段的值表示公历和朱利安日历中的第十二个月。
static intDST_OFFSET getset字段编号 get夏令时偏移量(以毫秒为单位)。
static intERA getset字段号表示时代,例如在儒略历中的AD或BC。
static intFEBRUARY MONTH字段的价值表示今年第二个月在公历和朱利安日历。
static intFIELD_COUNT getset的不同字段的数量。
protected int[]fields 该日历的当前设置时间的日历字段值。
static intFRIDAY DAY_OF_WEEK字段的值表示周五。
static intHOUR getset字段编号, get上午或下午的小时。
static intHOUR_OF_DAY get字段编号和 set当天的小时数。
protected boolean[]isSet 说明是否设置日历的指定日历字段的标志。
protected booleanisTimeSet 如果那么那么 time的值是有效的。
static intJANUARY MONTH字段的价值表示今年首次在公历和朱利安日历。
static intJULY MONTH字段的值代表了 公历和朱利安日历中的第七个月。
static intJUNE MONTH字段的价值 指示了公历和朱利安日历中的第六个月。
static intLONG getDisplayNamegetDisplayNames相当于 LONG_FORMAT的样式说明
static intLONG_FORMAT getDisplayNamegetDisplayNames样式说明 表示用于格式的长名称。
static intLONG_STANDALONE 一个 getDisplayNamegetDisplayNames样式说明 表示一个独立使用的长名称,例如月份名称作为日历头。
static intMARCH MONTH字段的值代表了 公历和朱利安日历中的第三个月。
static intMAY MONTH领域的价值 指示了公历和朱利安日历中的第五个月。
static intMILLISECOND getset字段号表示 get内的 set数。
static intMINUTE getset字段编号表示小时内的分钟。
static intMONDAY DAY_OF_WEEK字段的值表示星期一。
static intMONTH getset字段号表示月份。
static intNARROW_FORMAT getDisplayNamegetDisplayNames样式说明 表示用于格式的窄名称。
static intNARROW_STANDALONE getDisplayNamegetDisplayNames样式说明 独立地表示一个狭义的名称。
static intNOVEMBER MONTH领域的价值 指示了公历和朱利安日历中的第十一个月。
static intOCTOBER MONTH字段的价值表示在公历和朱利安日历中的一年中的第十个月。
static intPM AM_PM字段的值表示从中午到午夜之前的一天中的一段时间。
static intSATURDAY DAY_OF_WEEK字段的值表示星期六。
static intSECOND getset字段编号表示分钟内的第二个。
static intSEPTEMBER MONTH字段的值代表了 公历和朱利安日历中的第九个月。
static intSHORT getDisplayNamegetDisplayNames样式说明 相当于 SHORT_FORMAT
static intSHORT_FORMAT getDisplayNamegetDisplayNames样式说明 表示用于格式的短名称。
static intSHORT_STANDALONE 一个用于 getDisplayNamegetDisplayNames样式说明 表示一个简单的名称,例如一个月缩写作为日历头。
static intSUNDAY DAY_OF_WEEK字段的值表示星期天。
static intTHURSDAY DAY_OF_WEEK字段的值表示星期四。
protected longtime 这个日历的当前设定时间,以1970年1月1日,格林尼治标准时间0:00:00之后的毫秒表示。
static intTUESDAY DAY_OF_WEEK字段的值表示周二。
static intUNDECIMBER MONTH字段的值表示一年的第十三个月。
static intWEDNESDAY DAY_OF_WEEK字段的值表示周三。
static intWEEK_OF_MONTH getset字段编号, set当月的周数。
static intWEEK_OF_YEAR getset字段编号, set本年度的周数。
static intYEAR get现场编号和 set表示年份。
static intZONE_OFFSET getset字段编号, get GMT以毫秒为 get的原始偏移量。

第三代日期类

LocalDate

Modifier and TypeMethod and Description
TemporaladjustInto(Temporal temporal) 调整指定的时间对象与此对象的日期相同。
LocalDateTimeatStartOfDay() 将此日期与午夜时间结合 LocalDateTime ,在此日期开始时创建一个 LocalDateTime
ZonedDateTimeatStartOfDay(ZoneId zone) 根据时区中的规则,在最早的有效时间内从此日期返回划分的日期时间。
LocalDateTimeatTime(int hour, int minute) 结合此日期与时间创建一个 LocalDateTime
LocalDateTimeatTime(int hour, int minute, int second) 结合此日期与时间创建一个 LocalDateTime
LocalDateTimeatTime(int hour, int minute, int second, int nanoOfSecond) 结合此日期与时间创建一个 LocalDateTime
LocalDateTimeatTime(LocalTime time) 结合此日期与时间创建一个 LocalDateTime
OffsetDateTimeatTime(OffsetTime time) 将此日期与偏移时间相结合以创建 OffsetDateTime
intcompareTo(ChronoLocalDate other) 将此日期与另一个日期进行比较。
booleanequals(Object obj) 检查这个日期是否等于另一个日期。
Stringformat(DateTimeFormatter formatter) 使用指定的格式化程序格式化此日期。
static LocalDatefrom(TemporalAccessor temporal) 从时间对象获取一个 LocalDate的实例。
intget(TemporalField field) 从此日期获取指定字段的 int
IsoChronologygetChronology() 获取这个日期的时间顺序,即ISO日历系统。
intgetDayOfMonth() 获取月份字段。
DayOfWeekgetDayOfWeek() 获取星期几字段,这是一个枚举 DayOfWeek
intgetDayOfYear() 获得日期字段。
EragetEra() 获得这个时代适用的时代。
longgetLong(TemporalField field) 从此日期获取指定字段的值为 long
MonthgetMonth() 使用 Month枚举获取月份字段。
intgetMonthValue() 将月份字段从1到12。
intgetYear() 获取年份字段。
inthashCode() 这个日期的哈希码。
booleanisAfter(ChronoLocalDate other) 检查此日期是否在指定日期之后。
booleanisBefore(ChronoLocalDate other) 检查此日期是否在指定日期之前。
booleanisEqual(ChronoLocalDate other) 检查此日期是否等于指定的日期。
booleanisLeapYear() 根据ISO培训日历系统规则,检查年份是否是闰年。
booleanisSupported(TemporalField field) 检查指定的字段是否受支持。
booleanisSupported(TemporalUnit unit) 检查指定的单位是否受支持。
intlengthOfMonth() 返回由此日期表示的月份的长度。
intlengthOfYear() 返回由此日期表示的年份的长度。
LocalDateminus(long amountToSubtract, TemporalUnit unit) 返回此日期的副本,减去指定的金额。
LocalDateminus(TemporalAmount amountToSubtract) 返回此日期的副本,减去指定的金额。
LocalDateminusDays(long daysToSubtract) 返回此 LocalDate的副本,并减去指定的天数。
LocalDateminusMonths(long monthsToSubtract) 返回此 LocalDate的副本,指定的时间间隔减去。
LocalDateminusWeeks(long weeksToSubtract) 返回此 LocalDate一个副本,其中指定的周期以周为单位减去。
LocalDateminusYears(long yearsToSubtract) 返回此 LocalDate的副本,以减去的年份为单位。
static LocalDatenow() 从默认时区的系统时钟获取当前日期。
static LocalDatenow(Clock clock) 从指定的时钟获取当前日期。
static LocalDatenow(ZoneId zone) 从指定时区的系统时钟获取当前日期。
static LocalDateof(int year, int month, int dayOfMonth) 从一年,一个月和一天获得一个 LocalDate的实例。
static LocalDateof(int year, Month month, int dayOfMonth) 从一年,一个月和一天获得一个 LocalDate的实例。
static LocalDateofEpochDay(long epochDay) 从时代天数获得一个 LocalDate的实例。
static LocalDateofYearDay(int year, int dayOfYear) 从一年和一年的一年中获得 LocalDate的实例。
static LocalDateparse(CharSequence text) 从一个文本字符串(如 2007-12-03获取一个 LocalDate的实例。
static LocalDateparse(CharSequence text, DateTimeFormatter formatter) 使用特定格式化 LocalDate从文本字符串获取 LocalDate的实例。
LocalDateplus(long amountToAdd, TemporalUnit unit) 返回此日期的副本,并添加指定的金额。
LocalDateplus(TemporalAmount amountToAdd) 返回此日期的副本,并添加指定的金额。
LocalDateplusDays(long daysToAdd) 返回指定天数的 LocalDate的副本。
LocalDateplusMonths(long monthsToAdd) 返回这个 LocalDate的副本,其指定的时间段以月为单位。
LocalDateplusWeeks(long weeksToAdd) 返回这个 LocalDate的副本,并以指定的周期添加周数。
LocalDateplusYears(long yearsToAdd) 返回这个 LocalDate的副本,其中指定的时间段以添加的年数表示。
<R> Rquery(TemporalQuery<R> query) 使用指定的查询查询此日期。
ValueRangerange(TemporalField field) 获取指定字段的有效值的范围。
longtoEpochDay() 将此日期转换为大纪元日。
StringtoString() 将此日期输出为 String ,如 2007-12-03
Perioduntil(ChronoLocalDate endDateExclusive) 将此日期和其他日期之间的期间计算为 Period
longuntil(Temporal endExclusive, TemporalUnit unit) 根据指定的单位计算直到另一个日期的时间量。
LocalDatewith(TemporalAdjuster adjuster) 返回此日期的调整副本。
LocalDatewith(TemporalField field, long newValue) 返回此日期的副本,并将指定的字段设置为新值。
LocalDatewithDayOfMonth(int dayOfMonth) 返回此日期的副本,并更改日期。
LocalDatewithDayOfYear(int dayOfYear) 返回此日期的副本,并更改日期。
LocalDatewithMonth(int month) 返回这个日期的副本,并更改年月日。
LocalDatewithYear(int year) 返回此日期的副本,并更改年份。

LocalTime

Modifier and TypeMethod and Description
TemporaladjustInto(Temporal temporal) 调整指定的时间对象与此对象具有相同的时间。
LocalDateTimeatDate(LocalDate date) 结合这个时间与创建一个 LocalDateTime的日期。
OffsetTimeatOffset(ZoneOffset offset) 结合这个时间与偏移创建一个 OffsetTime
intcompareTo(LocalTime other) 比较这个 LocalTime到另一个时间。
booleanequals(Object obj) 检查这次是否等于另一次。
Stringformat(DateTimeFormatter formatter) 此时使用指定的格式化程序格式化。
static LocalTimefrom(TemporalAccessor temporal) 从时间对象获取一个 LocalTime的实例。
intget(TemporalField field) 从此时间获取指定字段的 int
intgetHour() 获取时间字段。
longgetLong(TemporalField field) 从此时间获取指定字段的值为 long
intgetMinute() 获取小时字段。
intgetNano() 获得纳秒第二场。
intgetSecond() 获得第二分钟的字段。
inthashCode() 这个时候的哈希码。
booleanisAfter(LocalTime other) 检查 LocalTime是否在指定的时间之后。
booleanisBefore(LocalTime other) 检查这个 LocalTime是否在指定的时间之前。
booleanisSupported(TemporalField field) 检查指定的字段是否受支持。
booleanisSupported(TemporalUnit unit) 检查指定的单位是否受支持。
LocalTimeminus(long amountToSubtract, TemporalUnit unit) 返回此次的副本,减去指定的金额。
LocalTimeminus(TemporalAmount amountToSubtract) 返回此次的副本,减去指定的金额。
LocalTimeminusHours(long hoursToSubtract) 以指定的时间段返回此 LocalTime的副本, LocalTime数字。
LocalTimeminusMinutes(long minutesToSubtract) 返回此 LocalTime的副本,其中指定的时间间隔以分钟为单位。
LocalTimeminusNanos(long nanosToSubtract) 以指定的时间段返回此 LocalTime的副本,以纳秒为单位。
LocalTimeminusSeconds(long secondsToSubtract) 返回此 LocalTime的副本,其中指定的时间间隔以秒为单位。
static LocalTimenow() 从默认时区的系统时钟获取当前时间。
static LocalTimenow(Clock clock) 从指定的时钟获取当前时间。
static LocalTimenow(ZoneId zone) 从指定时区的系统时钟获取当前时间。
static LocalTimeof(int hour, int minute) 从一小时分钟获取一个 LocalTime的实例。
static LocalTimeof(int hour, int minute, int second) 从一小时,一分钟和秒钟获得一个 LocalTime的实例。
static LocalTimeof(int hour, int minute, int second, int nanoOfSecond) 从一小时,分钟,秒和纳秒获取 LocalTime一个实例。
static LocalTimeofNanoOfDay(long nanoOfDay)LocalTime值获取 LocalTime的实例。
static LocalTimeofSecondOfDay(long secondOfDay) 从第二天的值获取一个 LocalTime的实例。
static LocalTimeparse(CharSequence text) 从一个文本字符串(如 10:15获取一个 LocalTime的实例。
static LocalTimeparse(CharSequence text, DateTimeFormatter formatter) 使用特定的格式化 LocalTime从文本字符串获取 LocalTime的实例。
LocalTimeplus(long amountToAdd, TemporalUnit unit) 返回此时添加了指定数量的副本。
LocalTimeplus(TemporalAmount amountToAdd) 返回此时添加了指定数量的副本。
LocalTimeplusHours(long hoursToAdd) 以指定的时间(以小时为单位)返回此 LocalTime的副本。
LocalTimeplusMinutes(long minutesToAdd) 以指定的时间(以分钟为单位)返回此 LocalTime的副本。
LocalTimeplusNanos(long nanosToAdd) 返回这个 LocalTime的副本,指定的时间段以纳秒为单位。
LocalTimeplusSeconds(long secondstoAdd) 以指定的时间段(以秒为单位)返回此 LocalTime的副本。
<R> Rquery(TemporalQuery<R> query) 此时使用指定的查询进行查询。
ValueRangerange(TemporalField field) 获取指定字段的有效值的范围。
longtoNanoOfDay() 提取时间为天数,从 024 * 60 * 60 * 1,000,000,000 - 1
inttoSecondOfDay() 提取时间为一天的时间,从 024 * 60 * 60 - 1
StringtoString() 此时输出为 String ,如 10:15
LocalTimetruncatedTo(TemporalUnit unit) 返回此 LocalTime的副本, LocalTime时间。
longuntil(Temporal endExclusive, TemporalUnit unit) 根据指定的单位计算直到另一次的时间量。
LocalTimewith(TemporalAdjuster adjuster) 返回此次调整后的副本。
LocalTimewith(TemporalField field, long newValue) 返回此时间的副本,并将指定的字段设置为新值。
LocalTimewithHour(int hour) 返回此日期值更改的 LocalTime的副本。
LocalTimewithMinute(int minute) 返回这个 LocalTime的副本,小时值更改。
LocalTimewithNano(int nanoOfSecond) 返回这个 LocalTime的副本,纳秒变化值。
LocalTimewithSecond(int second) 返回这个 LocalTime的副本,其中二分之一值更改。

LocalDateTime

Modifier and TypeMethod and Description
TemporaladjustInto(Temporal temporal) 调整指定的时间对象与此对象具有相同的日期和时间。
OffsetDateTimeatOffset(ZoneOffset offset) 将此日期时间与偏移量相结合以创建 OffsetDateTime
ZonedDateTimeatZone(ZoneId zone) 将此日期时间与时区相结合以创建 ZonedDateTime
intcompareTo(ChronoLocalDateTime<?> other) 将此日期时间与其他日期时间进行比较。
booleanequals(Object obj) 检查这个日期时间是否等于另一个日期时间。
Stringformat(DateTimeFormatter formatter) 使用指定的格式化程序格式化此日期时间。
static LocalDateTimefrom(TemporalAccessor temporal) 从时间对象获取一个 LocalDateTime的实例。
intget(TemporalField field) 从此日期时间获取指定字段的值为 int
intgetDayOfMonth() 获取月份字段。
DayOfWeekgetDayOfWeek() 获取星期几字段,这是一个枚举 DayOfWeek
intgetDayOfYear() 获得日期字段。
intgetHour() 获取时间字段。
longgetLong(TemporalField field) 从此日期时间获取指定字段的值为 long
intgetMinute() 获取小时字段。
MonthgetMonth() 使用 Month枚举获取月份字段。
intgetMonthValue() 将月份字段从1到12。
intgetNano() 获得纳秒第二场。
intgetSecond() 获得第二分钟的字段。
intgetYear() 获取年份字段。
inthashCode() 这个日期时间的哈希码。
booleanisAfter(ChronoLocalDateTime<?> other) 检查这个日期时间是否在指定的日期之后。
booleanisBefore(ChronoLocalDateTime<?> other) 检查此日期时间是否在指定的日期时间之前。
booleanisEqual(ChronoLocalDateTime<?> other) 检查此日期时间是否等于指定的日期时间。
booleanisSupported(TemporalField field) 检查指定的字段是否受支持。
booleanisSupported(TemporalUnit unit) 检查指定的单位是否受支持。
LocalDateTimeminus(long amountToSubtract, TemporalUnit unit) 返回此日期时间的副本,并减去指定的金额。
LocalDateTimeminus(TemporalAmount amountToSubtract) 返回此日期时间的副本,并减去指定的金额。
LocalDateTimeminusDays(long days) 返回此 LocalDateTime的副本,其中指定的时间间隔以天为单位。
LocalDateTimeminusHours(long hours) 以指定的时间段返回此 LocalDateTime的副本,以减少的小时数。
LocalDateTimeminusMinutes(long minutes) 返回此 LocalDateTime的副本,以指定的时间间隔减去。
LocalDateTimeminusMonths(long months) 返回此 LocalDateTime的副本,指定的时间以月为单位减去。
LocalDateTimeminusNanos(long nanos) 返回这个 LocalDateTime的副本,以指定的时间减去纳秒。
LocalDateTimeminusSeconds(long seconds) 返回此 LocalDateTime的副本,其中指定的时间间隔以秒为单位。
LocalDateTimeminusWeeks(long weeks) 返回此 LocalDateTime的副本,其中指定的周期以周为单位减去。
LocalDateTimeminusYears(long years) 返回此 LocalDateTime的副本,并以减去的年份为单位。
static LocalDateTimenow() 从默认时区的系统时钟获取当前的日期时间。
static LocalDateTimenow(Clock clock) 从指定的时钟获取当前的日期时间。
static LocalDateTimenow(ZoneId zone) 从指定时区的系统时钟获取当前的日期时间。
static LocalDateTimeof(int year, int month, int dayOfMonth, int hour, int minute) 从年,月,日,小时和分钟获得 LocalDateTime的实例,将第二和纳秒设置为零。
static LocalDateTimeof(int year, int month, int dayOfMonth, int hour, int minute, int second) 从年,月,日,小时,分钟和秒获得 LocalDateTime的实例,将纳秒设置为零。
static LocalDateTimeof(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond) 获取的实例 LocalDateTime从年,月,日,小时,分钟,秒和纳秒。
static LocalDateTimeof(int year, Month month, int dayOfMonth, int hour, int minute) 从年,月,日,小时和分钟获得 LocalDateTime的实例,将第二和纳秒设置为零。
static LocalDateTimeof(int year, Month month, int dayOfMonth, int hour, int minute, int second) 从年,月,日,小时,分钟和秒获得 LocalDateTime的实例,将纳秒设置为零。
static LocalDateTimeof(int year, Month month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond) 获取的实例 LocalDateTime从年,月,日,小时,分钟,秒和纳秒。
static LocalDateTimeof(LocalDate date, LocalTime time) 从日期和时间获取 LocalDateTime一个实例。
static LocalDateTimeofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset) 使用从1970-01-01T00:00:00Z的时代开始的秒数获得一个 LocalDateTime的实例。
static LocalDateTimeofInstant(Instant instant, ZoneId zone)Instant和区域ID获取一个 LocalDateTime的实例。
static LocalDateTimeparse(CharSequence text) 从一个文本字符串(如 2007-12-03T10:15:30获取一个 LocalDateTime的实例。
static LocalDateTimeparse(CharSequence text, DateTimeFormatter formatter) 使用特定的格式化 LocalDateTime从文本字符串获取 LocalDateTime的实例。
LocalDateTimeplus(long amountToAdd, TemporalUnit unit) 返回此日期时间的副本,并添加指定的金额。
LocalDateTimeplus(TemporalAmount amountToAdd) 返回此日期时间的副本,并添加指定的金额。
LocalDateTimeplusDays(long days) 返回此 LocalDateTime的副本,并以指定的时间段添加天数。
LocalDateTimeplusHours(long hours) 以指定的时间(以小时为单位)返回此 LocalDateTime的副本。
LocalDateTimeplusMinutes(long minutes) 以指定的时间(以分钟为单位)返回此 LocalDateTime的副本。
LocalDateTimeplusMonths(long months) 返回这个 LocalDateTime的副本,其中指定的时间段以月为单位。
LocalDateTimeplusNanos(long nanos) 返回这个 LocalDateTime的副本,其指定时间以纳秒为单位。
LocalDateTimeplusSeconds(long seconds) 以指定的时间段返回此 LocalDateTime的副本,以秒为单位。
LocalDateTimeplusWeeks(long weeks) 返回这个 LocalDateTime的副本,并以指定的周期添加周数。
LocalDateTimeplusYears(long years) 返回这个 LocalDateTime的副本,其中指定的时间段以添加的年数表示。
<R> Rquery(TemporalQuery<R> query) 使用指定的查询查询此日期时间。
ValueRangerange(TemporalField field) 获取指定字段的有效值的范围。
LocalDatetoLocalDate() 获得这个日期时间的 LocalDate一部分。
LocalTimetoLocalTime() 获得这个日期时间的 LocalTime一部分。
StringtoString() 将此日期时间输出为 String ,例如 2007-12-03T10:15:30
LocalDateTimetruncatedTo(TemporalUnit unit) 返回此 LocalDateTime的副本, LocalDateTime时间。
longuntil(Temporal endExclusive, TemporalUnit unit) 根据指定的单位计算到另一个日期时间的时间量。
LocalDateTimewith(TemporalAdjuster adjuster) 返回此日期时间的调整副本。
LocalDateTimewith(TemporalField field, long newValue) 返回此日期时间的副本,并将指定的字段设置为新值。
LocalDateTimewithDayOfMonth(int dayOfMonth) 返回此 LocalDateTime的副本。
LocalDateTimewithDayOfYear(int dayOfYear) 返回这个 LocalDateTime的副本,并更改日期。
LocalDateTimewithHour(int hour) 返回此日期值更改的 LocalDateTime的副本。
LocalDateTimewithMinute(int minute) 返回这个 LocalDateTime的副本,小时值更改。
LocalDateTimewithMonth(int month) 返回此年份更改的 LocalDateTime的副本。
LocalDateTimewithNano(int nanoOfSecond) 返回这个 LocalDateTime的副本,纳秒变化值。
LocalDateTimewithSecond(int second) 返回这个 LocalDateTime的副本,其中 LocalDateTime了第二分钟的值。
LocalDateTimewithYear(int year) 返回这个 LocalDateTime的副本,年份被更改。

DateTimeFormatter

Modifier and TypeMethod and Description
Stringformat(TemporalAccessor temporal) 使用此格式化程序格式化日期时间对象。
voidformatTo(TemporalAccessor temporal, Appendable appendable) 格式化一个日期时间对象到 Appendable使用这个格式化程序。
ChronologygetChronology() 获得在格式化期间使用的压倒一记的年表。
DecimalStylegetDecimalStyle() 获取在格式化期间使用的DecimalStyle。
LocalegetLocale() 获取格式化期间要使用的区域设置。
Set<TemporalField>getResolverFields() 获取在解析期间使用的解析器字段。
ResolverStylegetResolverStyle() 获取在解析过程中使用的解析器样式。
ZoneIdgetZone() 获取在格式化期间使用的覆盖区域。
static DateTimeFormatterofLocalizedDate(FormatStyle dateStyle) 返回ISO年表的区域设置特定日期格式。
static DateTimeFormatterofLocalizedDateTime(FormatStyle dateTimeStyle) 返回ISO时代的区域设置特定的日期时间格式化程序。
static DateTimeFormatterofLocalizedDateTime(FormatStyle dateStyle, FormatStyle timeStyle) 返回ISO时代的特定日期和时间格式。
static DateTimeFormatterofLocalizedTime(FormatStyle timeStyle) 返回ISO时代的区域设置特定时间格式。
static DateTimeFormatterofPattern(String pattern) 使用指定的模式创建格式化程序。
static DateTimeFormatterofPattern(String pattern, Locale locale) 使用指定的模式和区域设置创建格式化程序。
TemporalAccessorparse(CharSequence text) 完全解析产生时间对象的文本。
TemporalAccessorparse(CharSequence text, ParsePosition position) 使用此格式化器解析文本,提供对文本位置的控制。
<T> Tparse(CharSequence text, TemporalQuery<T> query) 完全解析产生指定类型对象的文本。
TemporalAccessorparseBest(CharSequence text, TemporalQuery<?>... queries) 完全解析产生指定类型之一的对象的文本。
static TemporalQuery<Period>parsedExcessDays() 一个查询,可以访问已解析的多余天数。
static TemporalQuery<Boolean>parsedLeapSecond() 提供访问是否解析了跨越秒的查询。
TemporalAccessorparseUnresolved(CharSequence text, ParsePosition position) 使用此格式化程序解析文本,而无需解析结果,用于高级用例。
FormattoFormat() 将此格式化程序作为 java.text.Format实例返回。
FormattoFormat(TemporalQuery<?> parseQuery) 将此格式化器返回为 java.text.Format实例,将使用指定的查询进行解析。
StringtoString() 返回底层格式化程序的描述。
DateTimeFormatterwithChronology(Chronology chrono) 使用新的覆盖年表返回此格式化程序的副本。
DateTimeFormatterwithDecimalStyle(DecimalStyle decimalStyle) 使用新的DecimalStyle返回此格式化程序的副本。
DateTimeFormatterwithLocale(Locale locale) 使用新的语言环境返回此格式化程序的副本。
DateTimeFormatterwithResolverFields(Set<TemporalField> resolverFields) 使用一组新的解析器字段返回此格式化程序的副本。
DateTimeFormatterwithResolverFields(TemporalField... resolverFields) 使用一组新的解析器字段返回此格式化程序的副本。
DateTimeFormatterwithResolverStyle(ResolverStyle resolverStyle) 使用新的解析器样式返回此格式化程序的副本。
DateTimeFormatterwithZone(ZoneId zone) 使用新的覆盖区域返回此格式化程序的副本。

Instant

Modifier and TypeMethod and Description
TemporaladjustInto(Temporal temporal) 调整指定的时间对象具有这个瞬间。
OffsetDateTimeatOffset(ZoneOffset offset) 将此瞬间与偏移组合起来创建一个 OffsetDateTime
ZonedDateTimeatZone(ZoneId zone) 将此瞬间与时区相结合,创建一个 ZonedDateTime
intcompareTo(Instant otherInstant) 将此瞬间与指定的时刻进行比较。
booleanequals(Object otherInstant) 检查这个瞬间是否等于指定的时刻。
static Instantfrom(TemporalAccessor temporal) 从时间对象获取一个 Instant的实例。
intget(TemporalField field) 从该时刻获取指定字段的 int
longgetEpochSecond() 从1970-01-01T00:00:00Z的Java时代获取秒数。
longgetLong(TemporalField field) 从该时刻获取指定字段的值为 long
intgetNano() 从第二个开始就从时间线获得纳秒的数量。
inthashCode() 返回此时刻的哈希码。
booleanisAfter(Instant otherInstant) 检查这个瞬间是否在指定的时刻之后。
booleanisBefore(Instant otherInstant) 检查这个时刻是否在指定的时刻之前。
booleanisSupported(TemporalField field) 检查指定的字段是否受支持。
booleanisSupported(TemporalUnit unit) 检查指定的单位是否受支持。
Instantminus(long amountToSubtract, TemporalUnit unit) 返回此时刻的副本,减去指定的金额。
Instantminus(TemporalAmount amountToSubtract) 返回此时刻的副本,减去指定的金额。
InstantminusMillis(long millisToSubtract) 以毫秒为单位的指定持续时间返回此瞬间的副本。
InstantminusNanos(long nanosToSubtract) 以纳秒为单位返回指定持续时间的此瞬间的副本。
InstantminusSeconds(long secondsToSubtract) 以秒为单位返回指定持续时间的此瞬间的副本。
static Instantnow() 从系统时钟获取当前瞬间。
static Instantnow(Clock clock) 从指定的时钟获取当前时刻。
static InstantofEpochMilli(long epochMilli) 获得的一个实例 Instant从1970-01-01T00划时代使用毫秒:00:00Z。
static InstantofEpochSecond(long epochSecond) 使用从1970-01-01T00:00:00Z的时代开始的秒数获得一个 Instant的实例。
static InstantofEpochSecond(long epochSecond, long nanoAdjustment) 使用从1970-01-01T00:00:00Z的时期开始的秒数获得 Instant的实例, Instant获得秒的纳秒分数。
static Instantparse(CharSequence text) 从一个文本字符串(如 2007-12-03T10:15:30.00Z获取一个 Instant的实例。
Instantplus(long amountToAdd, TemporalUnit unit) 返回添加指定数量的此瞬间的副本。
Instantplus(TemporalAmount amountToAdd) 返回添加指定数量的此瞬间的副本。
InstantplusMillis(long millisToAdd) 以毫秒为单位的指定持续时间返回此瞬间的副本。
InstantplusNanos(long nanosToAdd) 以指定的持续时间返回此瞬间的副本,以纳秒为单位。
InstantplusSeconds(long secondsToAdd) 以指定的持续时间返回此瞬间的副本,以秒为单位。
<R> Rquery(TemporalQuery<R> query) 使用指定的查询查询此即时。
ValueRangerange(TemporalField field) 获取指定字段的有效值的范围。
longtoEpochMilli() 将此瞬间转换为1970-01-01T00:00:00Z的时期的毫秒数。
StringtoString() 此瞬间使用ISO-8601表示形式的字符串表示形式。
InstanttruncatedTo(TemporalUnit unit) 返回此 Instant的副本截断到指定的单位。
longuntil(Temporal endExclusive, TemporalUnit unit) 根据指定单位计算直到另一瞬间的时间量。
Instantwith(TemporalAdjuster adjuster) 返回此瞬间的调整副本。
Instantwith(TemporalField field, long newValue) 将指定的字段设置为新值返回此瞬间的副本。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱学习的大雄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值