Class DateKit


public class DateKit extends Almanac
时间工具类
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • DateKit

      public DateKit()
  • Method Details

    • spendNt

      public static long spendNt(long preTime)
      计时,常用于记录某段代码的执行时间,单位:纳秒
      Parameters:
      preTime - 之前记录的时间
      Returns:
      时间差, 纳秒
    • spendMs

      public static long spendMs(long preTime)
      计时,常用于记录某段代码的执行时间,单位:毫秒
      Parameters:
      preTime - 之前记录的时间
      Returns:
      时间差, 毫秒
    • ageOfNow

      public static int ageOfNow(String birthDay)
      生日转为年龄,计算法定年龄
      Parameters:
      birthDay - 生日,标准日期字符串
      Returns:
      年龄
    • ageOfNow

      public static int ageOfNow(Date birthDay)
      生日转为年龄,计算法定年龄
      Parameters:
      birthDay - 生日
      Returns:
      年龄
    • getLastTime

      public static String getLastTime(Date date)
      返回文字描述的日期
      Parameters:
      date - 日期
      Returns:
      日期
    • range

      public static Boundary range(Date start, Date end, Fields.Type type)
      创建日期范围生成器
      Parameters:
      start - 起始日期时间
      end - 结束日期时间
      type - 步进单位
      Returns:
      Boundary
    • rangeContains

      public static List<DateTime> rangeContains(Boundary start, Boundary end)
      两个时间区间取交集
      Parameters:
      start - 开始区间
      end - 结束区间
      Returns:
      true 包含
    • rangeNotContains

      public static List<DateTime> rangeNotContains(Boundary start, Boundary end)
      两个时间区间取差集(end - start)
      Parameters:
      start - 开始区间
      end - 结束区间
      Returns:
      true 包含
    • rangeFunc

      public static <T> List<T> rangeFunc(Date start, Date end, Fields.Type type, Function<Date,T> func)
      按日期范围遍历,执行 function
      Type Parameters:
      T - Date经过函数处理结果类型
      Parameters:
      start - 起始日期时间(包括)
      end - 结束日期时间
      type - 步进单位
      func - 每次遍历要执行的 function
      Returns:
      结果列表
    • rangeConsume

      public static void rangeConsume(Date start, Date end, Fields.Type type, Consumer<Date> consumer)
      按日期范围遍历,执行 consumer
      Parameters:
      start - 起始日期时间(包括)
      end - 结束日期时间
      type - 步进单位
      consumer - 每次遍历要执行的 consumer
    • rangeToList

      public static List<DateTime> rangeToList(Date start, Date end, Fields.Type type)
      根据步进单位获取起始日期时间和结束日期时间的时间区间集合
      Parameters:
      start - 起始日期时间
      end - 结束日期时间
      type - 步进单位
      Returns:
      Boundary
    • rangeToList

      public static List<DateTime> rangeToList(Date start, Date end, Fields.Type type, int step)
      根据步进单位和步进获取起始日期时间和结束日期时间的时间区间集合
      Parameters:
      start - 起始日期时间
      end - 结束日期时间
      type - 步进单位
      step - 步进
      Returns:
      Boundary
    • getLunar

      public Lunar getLunar()
      通过公历构造
      Returns:
      Lunar
    • getLunar

      public Lunar getLunar(Calendar calendar)
      通过公历构造
      Parameters:
      calendar - 公历日期
      Returns:
      Lunar
    • getLunar

      public Lunar getLunar(int year, int month, int day)
      通过年、月、日构造
      Parameters:
      year - 农历年
      month - 农历月份,范围1-12
      day - 农历日1-30
      Returns:
      Lunar
    • getLunar

      public Lunar getLunar(int year, int month, int day, int hour, int minute)
      通过年、月、日构造
      Parameters:
      year - 农历年
      month - 农历月份,范围1-12
      day - 农历日1-30
      hour - 小时
      minute - 分钟
      Returns:
      Lunar
    • getLunar

      public Lunar getLunar(int year, int month, int day, int hour, int minute, int second)
      通过年、月、日构造
      Parameters:
      year - 农历年
      month - 农历月份,范围1-12
      day - 农历日1-30
      hour - 小时
      minute - 分钟
      second - 秒
      Returns:
      Lunar
    • getSolar

      public Solar getSolar()
      通过公历构造
      Returns:
      Solar
    • getSolar

      public Solar getSolar(Calendar calendar)
      通过公历构造
      Parameters:
      calendar - 公历日期
      Returns:
      Solar
    • getSolar

      public Solar getSolar(int year, int month, int day)
      通过年、月、日构造
      Parameters:
      year - 农历年
      month - 农历月份,范围1-12
      day - 农历日1-30
      Returns:
      Solar
    • getSolar

      public Solar getSolar(int year, int month, int day, int hour, int minute)
      通过年、月、日构造
      Parameters:
      year - 农历年
      month - 农历月份,范围1-12
      day - 农历日1-30
      hour - 小时
      minute - 分钟
      Returns:
      Solar
    • getSolar

      public Solar getSolar(int year, int month, int day, int hour, int minute, int second)
      通过年、月、日构造
      Parameters:
      year - 农历年
      month - 农历月份,范围1-12
      day - 农历日1-30
      hour - 小时
      minute - 分钟
      second - 秒
      Returns:
      Solar