类 DateTimeUtil

java.lang.Object
tech.mhuang.pacebox.core.date.DateTimeUtil

public class DateTimeUtil extends Object
时间转换工具类
从以下版本开始:
1.0.0
作者:
mhuang
  • 方法详细资料

    • dateToLocalDateTime

      public static LocalDateTime dateToLocalDateTime(Date date)
      将Data转换成JDK8中的LocalDateTime对象
      参数:
      date - 需要转换的Data对象
      返回:
      LocalDateTime 返回转换后的LocalDateTime对象
    • dateToLocalDate

      public static LocalDate dateToLocalDate(Date date)
      将Data转换成JDK8中的LocalDate对象
      参数:
      date - 需要转换的Data对象
      返回:
      LocalDate 返回转换后的LocalDate对象
    • localDateTimeToDate

      public static Date localDateTimeToDate(LocalDateTime localDateTime)
      将LocalDateTime转换成JDK8中的Date对象
      参数:
      localDateTime - 需要转换的LocalDateTime对象
      返回:
      Date 返回转换后的Date对象
    • localDateTimeToInstant

      public static Instant localDateTimeToInstant(LocalDateTime localDateTime)
      将LocalDateTime转换成JDK8中的Instant对象
      参数:
      localDateTime - 需要转换的LocalDateTime对象
      返回:
      instant
      从以下版本开始:
      1.1.8
    • dateToInstant

      public static Instant dateToInstant(Date date)
      将Date转换成JDK8中的Instant对象
      参数:
      date - 需要转换的Date对象
      返回:
      instant
      从以下版本开始:
      1.1.8
    • localDateToStartDate

      public static Date localDateToStartDate(LocalDate localDate)
      LocalDate转换成Data、时间取00:00:00
      参数:
      localDate - 需要转换的LocalDate
      返回:
      Date 转换后的Date
    • localDateToStartDate

      public static Date localDateToStartDate(String localDateStr)
      LocalDate转换成Data、时间取00:00:00
      参数:
      localDateStr - 需要转换的localDateStr
      返回:
      Date 转换后的Date
    • localDateToEndDate

      public static Date localDateToEndDate(LocalDate localDate)
      LocalDate转换成Data、时间取23:59:59
      参数:
      localDate - 需要转换的LocalDate
      返回:
      Date 转换后的Date
    • localDateToEndDate

      public static Date localDateToEndDate(String localDateStr)
      LocalDate转换成Data、时间取23:59:59
      参数:
      localDateStr - 需要转换的localDateStr
      返回:
      Date 转换后的Date
    • parseDateTime

      public static LocalDateTime parseDateTime(String dateTimeStr)
      将字符串按照yyyy-MM-dd HH:mm:ss转换成LocalDateTime
      参数:
      dateTimeStr - 转换的字符串
      返回:
      LocalDateTime 转换后的LocalDateTime对象
    • parseDateTime

      public static LocalDateTime parseDateTime(String dateTimeStr, String datePattern)
      将字符串按照yyyy-MM-dd HH:mm:ss转换成LocalDateTime
      参数:
      dateTimeStr - 转换的字符串
      datePattern - 转换规则
      返回:
      LocalDateTime 转换后的LocalDateTime对象
      从以下版本开始:
      1.1.4
    • parseDateTime

      public static LocalDateTime parseDateTime(String dateTimeStr, DateTimeFormatter formatter)
      将字符串按照yyyy-MM-dd HH:mm:ss转换成LocalDateTime
      参数:
      dateTimeStr - 转换的字符串
      formatter - 转换规则
      返回:
      LocalDateTime 转换后的LocalDateTime对象
      从以下版本开始:
      1.1.4
    • parseDateTimeToDate

      public static Date parseDateTimeToDate(String dateTimeStr)
      将字符串按照yyyy-MM-dd HH:mm:ss转成Date对象
      参数:
      dateTimeStr - 转换的字符串
      返回:
      Date 转换后的Date对象
    • fromDateTime

      public static String fromDateTime(LocalDateTime localDateTime)
      将LocalDateTime对象转换成字符串、格式为:yyyy-MM-dd HH:mm:ss
      参数:
      localDateTime - 转换的对象
      返回:
      String 转换后存放的字符串
    • fromDateTime

      public static String fromDateTime(LocalDateTime localDateTime, String formatString)
      将LocalDateTime对象转换成字符串、格式可自定义、比如:yyyy-MM-dd HH:mm:ss
      参数:
      localDateTime - 转换的对象
      formatString - 转换的格式
      返回:
      String 转换后存放的字符串
    • fromDateTime

      public static String fromDateTime(LocalDateTime localDateTime, DateTimeFormatter formatter)
      将LocalDateTime对象转换成字符串、格式可自定义、比如:DateTimeFormatter.ofPattern(yyyy-MM-dd HH:mm:ss)
      参数:
      localDateTime - 转换的对象
      formatter - 转换的格式类
      返回:
      String 转换后存放的字符串
    • unitToDateTime

      public static LocalDateTime unitToDateTime(Long unit)
      将unit时间戳转换成LocalDateTime对象
      参数:
      unit - 时间戳(毫秒级 13位)
      返回:
      LocalDateTime 转换后的时间对象
    • getTimestampOfDateTime

      public static long getTimestampOfDateTime(LocalDateTime localDateTime)
      将LocalDateTime转换成unit时间戳、毫秒级
      参数:
      localDateTime - 转换的对象
      返回:
      long 转换后的时间戳毫秒级
    • localDateIsThisWeek

      public static boolean localDateIsThisWeek(LocalDate date)
      判断日期是不是在当前周
      参数:
      date - 日期
      返回:
      是否是当前周
    • localDateToThisWeekList

      public static List<LocalDate> localDateToThisWeekList(LocalDate date)
      获取某天当前一周的日期
      参数:
      date - 某天
      返回:
      返回一周的日期
    • format

      public static String format(Date date, String format)
      date转字符串
      参数:
      date - date
      format - format
      返回:
      结果集
      从以下版本开始:
      1.1.6
    • format

      public static String format(Date date, DateTimeFormatter format)
      date转字符串
      参数:
      date - date
      format - format
      返回:
      结果集
      从以下版本开始:
      1.1.6
    • localDateToThisMonthList

      public static List<LocalDate> localDateToThisMonthList(LocalDate date)
      获取某天当前一个月的日期
      参数:
      date - 某天
      返回:
      返回一月的日期
    • getMonthDayNumByLocalDate

      public static int getMonthDayNumByLocalDate(LocalDate date)
      获取某日期当月的天数
      参数:
      date - 某日期
      返回:
      天数
    • getLocalDateDiffDay

      public static Long getLocalDateDiffDay(LocalDate before, LocalDate after)
      判断开始时间到结束时间相差天数
      参数:
      before - 开始日期
      after - 结束日期
      返回:
      相差天数, 主要是结束-开始
    • currentDate

      public static Date currentDate()
      获取当前的Data
      返回:
      返回当前的Data对象