Class DateTool

java.lang.Object
com.xxl.tool.core.DateTool

public class DateTool extends Object
date util
Author:
xuxueli 2018-08-19 01:24:11
  • Field Details

  • Constructor Details

    • DateTool

      public DateTool()
  • Method Details

    • parse

      public static Date parse(String dateString, String pattern)
      parse String to Date, with time
      Parameters:
      dateString -
      pattern -
      Returns:
      date
    • parseDateTime

      public static Date parseDateTime(String dateString)
      parse String to DateTime, like "yyyy-MM-dd HH:mm:s"
      Parameters:
      dateString -
      Returns:
    • parseDate

      public static Date parseDate(String dateString)
      parse String to Date, like "yyyy-MM-dd"
      Parameters:
      dateString -
      Returns:
    • format

      public static String format(Date date, String pattern)
      format Date to String
      Parameters:
      date - date
      pattern - pattern
      Returns:
      date string
    • formatDate

      public static String formatDate(Date date)
      format date;like "yyyy-MM-dd"
      Parameters:
      date -
      Returns:
      Throws:
      ParseException
    • formatDateTime

      public static String formatDateTime(Date date)
      format date;like "yyyy-MM-dd HH:mm:s"
      Parameters:
      date -
      Returns:
      Throws:
      ParseException
    • parseLocalDateTime

      public static LocalDateTime parseLocalDateTime(String dateString, String pattern)
      parse String to LocalDateTime
      Parameters:
      dateString -
      pattern -
      Returns:
    • parseLocalDate

      public static LocalDate parseLocalDate(String dateString, String pattern)
      parse String to LocalDate
      Parameters:
      dateString -
      pattern -
      Returns:
    • parseLocalTime

      public static LocalTime parseLocalTime(String dateString, String pattern)
      parse String to LocalTime
      Parameters:
      dateString -
      pattern -
      Returns:
    • parseYearMonth

      public static YearMonth parseYearMonth(String dateString, String pattern)
      parse String to YearMonth
      Parameters:
      dateString -
      pattern -
      Returns:
    • formatTemporal

      public static String formatTemporal(Temporal temporal, String pattern)
      format temporal to String
      Parameters:
      temporal -
      pattern -
      Returns:
    • addYears

      public static Date addYears(Date date, long amount)
      add Years
      Parameters:
      date -
      amount -
      Returns:
    • addMonths

      public static Date addMonths(Date date, long amount)
      add Months
      Parameters:
      date -
      amount -
      Returns:
    • addDays

      public static Date addDays(Date date, long amount)
      add Days
      Parameters:
      date -
      amount -
      Returns:
    • addHours

      public static Date addHours(Date date, long amount)
      add Hours
      Parameters:
      date -
      amount -
      Returns:
    • addMinutes

      public static Date addMinutes(Date date, long amount)
      add Minutes
      Parameters:
      date -
      amount -
      Returns:
    • addSeconds

      public static Date addSeconds(Date date, long amount)
      add Seconds
      Parameters:
      date -
      amount -
      Returns:
    • addWeeks

      public static Date addWeeks(Date date, long amount)
      add Weeks
      Parameters:
      date -
      amount -
      Returns:
    • addMilliseconds

      public static Date addMilliseconds(Date date, long amount)
      add Milliseconds
      Parameters:
      date -
      amount -
      Returns:
    • set

      public static Date set(Date date, int calendarField, int amount)
      Set the specified field to a date, returning a new object.
      Parameters:
      date - the original is unchanged,
      calendarField - like "Calendar.YEAR"
      amount - the amount to set
      Returns:
    • setYears

      public static Date setYears(Date date, int amount)
      set year to a date, returning a new object
      Parameters:
      date - the original is unchanged,
      amount - the amount to set
      Returns:
    • setMonths

      public static Date setMonths(Date date, int amount)
      set month to a date, returning a new object
      Parameters:
      date - the first month of the year is JANUARY, which is 0;
      amount - the amount to set
      Returns:
    • setDays

      public static Date setDays(Date date, int amount)
      set day-of-month to a date, returning a new object
      Parameters:
      date - the original is unchanged,
      amount - the amount to set
      Returns:
    • setHours

      public static Date setHours(Date date, int amount)
      set hour-of-day to a date, returning a new object
      Parameters:
      date - the original is unchanged,
      amount - the amount to set
      Returns:
    • setMinutes

      public static Date setMinutes(Date date, int amount)
      set minutes to a date, returning a new object
      Parameters:
      date - the original is unchanged,
      amount - the amount to set
      Returns:
    • setSeconds

      public static Date setSeconds(Date date, int amount)
      set seconds to a date, returning a new object
      Parameters:
      date - the original is unchanged,
      amount - the amount to set
      Returns:
    • setMilliseconds

      public static Date setMilliseconds(Date date, int amount)
      set milliseconds to a date, returning a new object
      Parameters:
      date - the original is unchanged,
      amount - the amount to set
      Returns:
    • setStartOfDay

      public static Date setStartOfDay(Date date)
      set start of day to a date, like "yyyy-MM-dd 00:00:00"
      Parameters:
      date - the original is unchanged,
      Returns:
      return the start of day, like "yyyy-MM-dd 00:00:00"
    • betweenYear

      public static long betweenYear(Date beginDate, Date endDate)
      between year
      Parameters:
      beginDate -
      endDate -
      Returns:
    • betweenMonth

      public static long betweenMonth(Date beginDate, Date endDate)
      between month
      Parameters:
      beginDate -
      endDate -
      Returns:
    • betweenDay

      public static long betweenDay(Date beginDate, Date endDate)
      between day
      Parameters:
      beginDate -
      endDate -
      Returns:
    • betweenHour

      public static long betweenHour(Date beginDate, Date endDate)
      between hour
      Parameters:
      beginDate -
      endDate -
      Returns:
    • betweenMinute

      public static long betweenMinute(Date beginDate, Date endDate)
      between minute
      Parameters:
      beginDate -
      endDate -
      Returns:
    • betweenSecond

      public static long betweenSecond(Date beginDate, Date endDate)
      between second
      Parameters:
      beginDate -
      endDate -
      Returns:
    • betweenWeek

      public static long betweenWeek(Date beginDate, Date endDate)
      between week
      Parameters:
      beginDate -
      endDate -
      Returns:
    • isSameDay

      public static boolean isSameDay(Calendar cal1, Calendar cal2)
      is same day
      Parameters:
      cal1 -
      cal2 -
      Returns: