Class Between

java.lang.Object
org.miaixz.bus.core.center.date.Between
All Implemented Interfaces:
Serializable

public class Between extends Object implements Serializable
日期间隔
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Between(Date begin, Date end)
    构造 在前的日期做为起始时间,在后的做为结束时间,间隔只保留绝对值正数
    Between(Date begin, Date end, boolean isAbs)
    构造 在前的日期做为起始时间,在后的做为结束时间
  • Method Summary

    Modifier and Type
    Method
    Description
    static Period
    between(LocalDate startTimeInclude, LocalDate endTimeExclude)
    获取两个日期的表象时间差,如果结束时间早于开始时间,获取结果为负。 比如2011年2月1日,和2021年8月11日,日相差了10天,月相差6月
    static Duration
    between(LocalDateTime startTimeInclude, LocalDateTime endTimeExclude)
    获取两个日期的差,如果结束时间早于开始时间,获取结果为负 返回结果为Duration对象,通过调用toXXX方法返回相差单位
    static long
    between(LocalDateTime startTimeInclude, LocalDateTime endTimeExclude, ChronoUnit unit)
    获取两个日期的差,如果结束时间早于开始时间,获取结果为负 返回结果为时间差的long值
    static Duration
    between(Temporal startTimeInclude, Temporal endTimeExclude)
    获取两个日期的差,如果结束时间早于开始时间,获取结果为负。 返回结果为Duration对象,通过调用toXXX方法返回相差单位
    static long
    between(Temporal startTimeInclude, Temporal endTimeExclude, ChronoUnit unit)
    获取两个日期的差,如果结束时间早于开始时间,获取结果为负。 返回结果为时间差的long值
    long
    between(Units unit)
    判断两个日期相差的时长 返回 给定单位的时长差
    long
    betweenMonth(boolean isReset)
    计算两个日期相差月数 在非重置情况下,如果起始日期的天大于结束日期的天,月数要少算1(不足1个月)
    long
    betweenYear(boolean isReset)
    计算两个日期相差年数 在非重置情况下,如果起始日期的月大于结束日期的月,年数要少算1(不足1年)
    获取开始时间
    获取结束日期
    static Between
    of(Date begin, Date end)
    创建 在前的日期做为起始时间,在后的做为结束时间,间隔只保留绝对值正数
    static Between
    of(Date begin, Date end, boolean isAbs)
    创建 在前的日期做为起始时间,在后的做为结束时间,间隔只保留绝对值正数
     
    格式化输出时间差
    格式化输出时间差

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Between

      public Between(Date begin, Date end)
      构造 在前的日期做为起始时间,在后的做为结束时间,间隔只保留绝对值正数
      Parameters:
      begin - 起始时间
      end - 结束时间
    • Between

      public Between(Date begin, Date end, boolean isAbs)
      构造 在前的日期做为起始时间,在后的做为结束时间
      Parameters:
      begin - 起始时间
      end - 结束时间
      isAbs - 日期间隔是否只保留绝对值正数
  • Method Details

    • of

      public static Between of(Date begin, Date end)
      创建 在前的日期做为起始时间,在后的做为结束时间,间隔只保留绝对值正数
      Parameters:
      begin - 起始时间
      end - 结束时间
      Returns:
      Between
    • of

      public static Between of(Date begin, Date end, boolean isAbs)
      创建 在前的日期做为起始时间,在后的做为结束时间,间隔只保留绝对值正数
      Parameters:
      begin - 起始时间
      end - 结束时间
      isAbs - 日期间隔是否只保留绝对值正数
      Returns:
      Between
    • between

      public static Duration between(Temporal startTimeInclude, Temporal endTimeExclude)
      获取两个日期的差,如果结束时间早于开始时间,获取结果为负。 返回结果为Duration对象,通过调用toXXX方法返回相差单位
      Parameters:
      startTimeInclude - 开始时间(包含)
      endTimeExclude - 结束时间(不包含)
      Returns:
      时间差 Duration对象
    • between

      public static Duration between(LocalDateTime startTimeInclude, LocalDateTime endTimeExclude)
      获取两个日期的差,如果结束时间早于开始时间,获取结果为负 返回结果为Duration对象,通过调用toXXX方法返回相差单位
      Parameters:
      startTimeInclude - 开始时间(包含)
      endTimeExclude - 结束时间(不包含)
      Returns:
      时间差 Duration对象
      See Also:
    • between

      public static long between(Temporal startTimeInclude, Temporal endTimeExclude, ChronoUnit unit)
      获取两个日期的差,如果结束时间早于开始时间,获取结果为负。 返回结果为时间差的long值
      Parameters:
      startTimeInclude - 开始时间(包括)
      endTimeExclude - 结束时间(不包括)
      unit - 时间差单位
      Returns:
      时间差
    • between

      public static long between(LocalDateTime startTimeInclude, LocalDateTime endTimeExclude, ChronoUnit unit)
      获取两个日期的差,如果结束时间早于开始时间,获取结果为负 返回结果为时间差的long值
      Parameters:
      startTimeInclude - 开始时间(包括)
      endTimeExclude - 结束时间(不包括)
      unit - 时间差单位
      Returns:
      时间差
    • between

      public static Period between(LocalDate startTimeInclude, LocalDate endTimeExclude)
      获取两个日期的表象时间差,如果结束时间早于开始时间,获取结果为负。 比如2011年2月1日,和2021年8月11日,日相差了10天,月相差6月
      Parameters:
      startTimeInclude - 开始时间(包括)
      endTimeExclude - 结束时间(不包括)
      Returns:
      时间差
    • between

      public long between(Units unit)
      判断两个日期相差的时长 返回 给定单位的时长差
      Parameters:
      unit - 相差的单位:相差 天Units.DAY、小时Units.HOUR
      Returns:
      时长差
    • betweenMonth

      public long betweenMonth(boolean isReset)
      计算两个日期相差月数 在非重置情况下,如果起始日期的天大于结束日期的天,月数要少算1(不足1个月)
      Parameters:
      isReset - 是否重置时间为起始时间(重置天时分秒)
      Returns:
      相差月数
    • betweenYear

      public long betweenYear(boolean isReset)
      计算两个日期相差年数 在非重置情况下,如果起始日期的月大于结束日期的月,年数要少算1(不足1年)
      Parameters:
      isReset - 是否重置时间为起始时间(重置月天时分秒)
      Returns:
      相差年数
    • getBegin

      public Date getBegin()
      获取开始时间
      Returns:
      获取开始时间
    • getEnd

      public Date getEnd()
      获取结束日期
      Returns:
      结束日期
    • toString

      public String toString(Units unit, FormatPeriod.Level level)
      格式化输出时间差
      Parameters:
      unit - 日期单位
      level - 级别
      Returns:
      字符串
    • toString

      public String toString(FormatPeriod.Level level)
      格式化输出时间差
      Parameters:
      level - 级别
      Returns:
      字符串
    • toString

      public String toString()
      Overrides:
      toString in class Object