Class MGL_DateTimeUtils

java.lang.Object
tech.mgl.core.utils.MGL_DateTimeUtils

public class MGL_DateTimeUtils extends Object
  • Constructor Details

    • MGL_DateTimeUtils

      public MGL_DateTimeUtils()
  • Method Details

    • calculateAge

      public static int calculateAge(LocalDate birthDate)
    • calculateAge

      public static int calculateAge(Date birthDate)
    • getMonths

      public static int getMonths(Date startDate, Date endDate)
    • getMonths

      public static int getMonths(LocalDate startDate, LocalDate endDate)
    • getDays

      public static long getDays(Date startDate, Date endDate)
    • getDays

      public static long getDays(LocalDate startDate, LocalDate endDate)
    • getInterval

      public static long getInterval(LocalDateTime start, LocalDateTime end)
      获取两个时间之间的间隔时间(LocalDateTime版本)
      Parameters:
      start - 开始时间,必须是 LocalDateTime
      end - 结束时间,必须是 LocalDateTime
      Returns:
      间隔时间,返回 -1 表示参数无效
    • getInterval

      public static long getInterval(LocalDateTime start, LocalDateTime end, MGL_DateTimeUtils.TimeUnit unit)
    • getInterval

      public static long getInterval(Date start, Date end)
      获取两个时间之间的间隔时间(Date版本)
      Parameters:
      start - 开始时间,必须是 Date
      end - 结束时间,必须是 Date
      Returns:
      间隔时间,返回 -1 表示参数无效
    • getInterval

      public static long getInterval(Date start, Date end, MGL_DateTimeUtils.TimeUnit unit)
    • convertToLocalDateTime

      public static LocalDateTime convertToLocalDateTime(Date dateTime)
      将 Date 转换为 LocalDateTime
      Parameters:
      dateTime - 时间对象,必须是 Date
      Returns:
      转换后的 LocalDateTime
    • convertToDate

      public static Date convertToDate(LocalDate localDate)
    • convertToLocalDate

      public static LocalDate convertToLocalDate(Date date)
    • main

      public static void main(String[] args)