程序包 org.anyline.util

类 DateUtil

java.lang.Object
org.anyline.util.DateUtil

public class DateUtil extends Object
  • 字段详细资料

    • FORMAT_FULL

      public static final String FORMAT_FULL
      另请参阅:
    • FORMAT_DATE_TIME

      public static final String FORMAT_DATE_TIME
      另请参阅:
    • FORMAT_DATE

      public static final String FORMAT_DATE
      另请参阅:
    • FORMAT_TIME

      public static final String FORMAT_TIME
      另请参阅:
    • DATE_PART_YEAR

      public static final int DATE_PART_YEAR
      另请参阅:
    • DATE_PART_MONTH

      public static final int DATE_PART_MONTH
      另请参阅:
    • DATE_PART_DATE

      public static final int DATE_PART_DATE
      另请参阅:
    • DATE_PART_DAY_OF_YEAR

      public static final int DATE_PART_DAY_OF_YEAR
      另请参阅:
    • DATE_PART_HOUR

      public static final int DATE_PART_HOUR
      另请参阅:
    • DATE_PART_MINUTE

      public static final int DATE_PART_MINUTE
      另请参阅:
    • DATE_PART_SECOND

      public static final int DATE_PART_SECOND
      另请参阅:
    • DATE_PART_MILLISECOND

      public static final int DATE_PART_MILLISECOND
      另请参阅:
  • 构造器详细资料

    • DateUtil

      public DateUtil()
  • 方法详细资料

    • between

      public static boolean between(Date cur, Date fr, Date to)
      cur是否在fr与to之间(包含fr, to)
      参数:
      cur - 时间
      fr - 开始时间
      to - 结束时间
      返回:
      boolean
    • between

      public static boolean between(String cur, String fr, String to)
      cur是否在fr与to之间(包含fr, to)
      参数:
      cur - 时间
      fr - 开始时间
      to - 结束时间
      返回:
      boolean
    • diff

      public static long diff(int part, Date fr, Date to)
      时间差
      参数:
      part - 参考Calendar
      fr - 开始时间
      to - 结束时间
      返回:
      long
    • diff

      public static long diff(int part, String fr, String to)
    • diff

      public static long diff(int part, Date fr)
    • diff

      public static long diff(int part, String fr)
    • format

      public static String format(Locale locale, ZoneId zone, Date date, String format)
      格式化日期
      参数:
      locale - 地区/语言, 格式化月份, 星期几时根据地区语言, 如MMMMM(zh:一月, en:January)MMMM(zh:一月, en:Jan) EEE(zh:星期五, en:Fri) EEEE(en:Friday)
        Symbol  Meaning                     Presentation      Examples
        ------  -------                     ------------      -------
         G       era                         text              AD; Anno Domini; A
         u       year                        year              2005; 04
         y       year-of-era                 year              2005; 04
         D       day-of-year                 number            189
         M/L     month-of-year               number/text       7; 07; Jul; July; J
         d       day-of-month                number            10
         g       modified-julian-day         number            2451334
      
         Q/q     quarter-of-year             number/text       3; 03; Q3; 3rd quarter
         Y       week-based-year             year              1996; 96
         w       week-of-week-based-year     number            27
         W       week-of-month               number            4
         E       day-of-week                 text              Tue; Tuesday; T
         e/c     localized day-of-week       number/text       2; 02; Tue; Tuesday; T
         F       day-of-week-in-month        number            3
      
         a       am-pm-of-day                text              PM
         B       period-of-day               text              in the morning
         h       clock-hour-of-am-pm (1-12)  number            12
         K       hour-of-am-pm (0-11)        number            0
         k       clock-hour-of-day (1-24)    number            24
      
         H       hour-of-day (0-23)          number            0
         m       minute-of-hour              number            30
         s       second-of-minute            number            55
         S       fraction-of-second          fraction          978
         A       milli-of-day                number            1234
         n       nano-of-second              number            987654321
         N       nano-of-day                 number            1234000000
      
         V       time-zone ID                zone-id           America/Los_Angeles; Z; -08:30
         v       generic time-zone name      zone-name         PT, Pacific Time
         z       time-zone name              zone-name         Pacific Standard Time; PST
         O       localized zone-offset       offset-O          GMT+8; GMT+08:00; UTC-08:00;
         X       zone-offset 'Z' for zero    offset-X          Z; -08; -0830; -08:30; -083015; -08:30:15
         x       zone-offset                 offset-x          +0000; -08; -0830; -08:30; -083015; -08:30:15
         Z       zone-offset                 offset-Z          +0000; -0800; -08:00
      
         p       pad next                    pad modifier      1
      
         '       escape for text             delimiter
         ''      single quote                literal           '
         [       optional section start
         ]       optional section end
         #       reserved for future use
         {       reserved for future use
         }       reserved for future use
       
      date - 日期
      format - 格式
      返回:
      String
    • format

      public static String format(Locale locale, ZoneId zone, Long date, String format)
    • format

      public static String format(Locale locale, ZoneId zone)
    • format

      public static String format(Locale locale, ZoneId zone, String format)
    • format

      public static String format(Locale locale, ZoneId zone, Date date)
    • format

      public static String format(Locale locale, ZoneId zone, Long date)
    • format

      public static String format(Locale locale, ZoneId zone, String date, String format)
    • format

      public static String format(Locale locale, Date date, String format)
    • format

      public static String format(Locale locale, Long date, String format)
    • format

      public static String format(Locale locale)
    • format

      public static String format(Locale locale, String format)
    • format

      public static String format(Locale locale, Date date)
    • format

      public static String format(Locale locale, Long date)
    • format

      public static String format(Locale locale, String date, String format)
    • format

      public static String format(Date date, String format)
    • format

      public static String format(Long date, String format)
    • format

      public static String format()
    • format

      public static String format(String format)
    • format

      public static String format(Date date)
    • format

      public static String format(Long date)
    • format

      public static String format(String date, String format)
    • convertMinute

      public static int convertMinute(String hm)
      时间转换成分钟
      参数:
      hm - 时间(10:10=610)
      返回:
      int
    • convertMinute

      public static int convertMinute()
    • convertMinute

      public static String convertMinute(int minute)
      分钟转换成时间
      参数:
      minute - 分钟(610=10:10)
      返回:
      String
    • getWeek

      public static String getWeek(Date date)
      星期几
      参数:
      date - 日期
      返回:
      String
    • getWeek

      public static String getWeek(String date)
    • getFirstDayOfWeek

      public static Date getFirstDayOfWeek(Date date)
      当周第一天 周日作为一周的第一天
      参数:
      date - 日期
      返回:
      Date
    • getFirstDayOfWeek

      public static Date getFirstDayOfWeek(String date)
    • getFirstDayOfWeek

      public static Date getFirstDayOfWeek()
    • getFirstDayOfNextWeek

      public static Date getFirstDayOfNextWeek(Date date)
      下周第一天
      参数:
      date - 日期
      返回:
      Date
    • getFirstDayOfNextWeek

      public static Date getFirstDayOfNextWeek(String date)
    • getFirstDayOfNextWeek

      public static Date getFirstDayOfNextWeek()
    • getFirstDayOfPreviousWeek

      public static Date getFirstDayOfPreviousWeek(Date date)
      上个周第一天
      参数:
      date - 日期
      返回:
      Date
    • getFirstDayOfPreviousWeek

      public static Date getFirstDayOfPreviousWeek(String date)
    • getFirstDayOfPreviousWeek

      public static Date getFirstDayOfPreviousWeek()
    • getLastDayOfWeek

      public static Date getLastDayOfWeek(Date date)
      当周最后天
      参数:
      date - 日期
      返回:
      Date
    • getLastDayOfWeek

      public static Date getLastDayOfWeek(String date)
    • getLastDayOfWeek

      public static Date getLastDayOfWeek()
    • getLastDayOfNextWeek

      public static Date getLastDayOfNextWeek(Date date)
      下周最后天
      参数:
      date - 日期
      返回:
      Date
    • getLastDayOfNextWeek

      public static Date getLastDayOfNextWeek(String date)
    • getLastDayOfNextWeek

      public static Date getLastDayOfNextWeek()
    • getLastDayOfPreviousWeek

      public static Date getLastDayOfPreviousWeek(Date date)
      上个周最后天
      参数:
      date - 日期
      返回:
      Date
    • getLastDayOfPreviousWeek

      public static Date getLastDayOfPreviousWeek(String date)
    • getLastDayOfPreviousWeek

      public static Date getLastDayOfPreviousWeek()
    • getFirstDayOfMonth

      public static Date getFirstDayOfMonth(Date date)
      当月第一天
      参数:
      date - 日期
      返回:
      Date
    • getFirstDayOfMonth

      public static Date getFirstDayOfMonth(String date)
    • getFirstDayOfMonth

      public static Date getFirstDayOfMonth()
    • getFirstDayOfNextMonth

      public static Date getFirstDayOfNextMonth(Date date)
      下个月第一天
      参数:
      date - 日期
      返回:
      Date
    • getFirstDayOfNextMonth

      public static Date getFirstDayOfNextMonth(String date)
    • getFirstDayOfNextMonth

      public static Date getFirstDayOfNextMonth()
    • getFirstDayOfPreviousMonth

      public static Date getFirstDayOfPreviousMonth(Date date)
      上个月第一天
      参数:
      date - 日期
      返回:
      Date
    • getFirstDayOfPreviousMonth

      public static Date getFirstDayOfPreviousMonth(String date)
    • getFirstDayOfPreviousMonth

      public static Date getFirstDayOfPreviousMonth()
    • getLastDayOfMonth

      public static Date getLastDayOfMonth(Date date)
      当月最后一天
      参数:
      date - 日期
      返回:
      Date
    • getLastDayOfMonth

      public static Date getLastDayOfMonth(String date)
    • getLastDayOfMonth

      public static Date getLastDayOfMonth()
    • getLastDayOfPreviousMonth

      public static Date getLastDayOfPreviousMonth(Date date)
      上月最后一天
      参数:
      date - 日期
      返回:
      Date
    • getLastDayOfPreviousMonth

      public static Date getLastDayOfPreviousMonth(String date)
    • getLastDayOfPreviousMonth

      public static Date getLastDayOfPreviousMonth()
    • getLastDayOfNextMonth

      public static Date getLastDayOfNextMonth(Date date)
      下月最后一天
      参数:
      date - 日期
      返回:
      Date
    • getLastDayOfNextMonth

      public static Date getLastDayOfNextMonth(String date)
    • getLastDayOfNextMonth

      public static Date getLastDayOfNextMonth()
    • getCurrentWeekday

      public static Date getCurrentWeekday(Date date)
    • getCurrentWeekday

      public static Date getCurrentWeekday(String date)
    • getCurrentWeekday

      public static Date getCurrentWeekday()
    • getMondayPlus

      public static int getMondayPlus(Date date)
    • getMondayPlus

      public static int getMondayPlus()
    • getMondayOFWeek

      public static Date getMondayOFWeek(Date date)
    • getMondayOFWeek

      public static Date getMondayOFWeek(String date)
    • getMondayOFWeek

      public static Date getMondayOFWeek()
    • getNextMonday

      public static Date getNextMonday(Date date)
    • getNextMonday

      public static Date getNextMonday(String date)
    • getNextMonday

      public static Date getNextMonday()
    • getNextSunday

      public static Date getNextSunday(Date date)
    • getNextSunday

      public static Date getNextSunday(String date)
    • getNextSunday

      public static Date getNextSunday()
    • getMonthPlus

      public static int getMonthPlus(Date date)
    • getNextYearEnd

      public static Date getNextYearEnd(Date date)
      明年最后一天的日期
      参数:
      date - 日期
      返回:
      Date
    • getNextYearEnd

      public static Date getNextYearEnd(String date)
    • getNextYearEnd

      public static Date getNextYearEnd()
    • getNextYearFirst

      public static Date getNextYearFirst(Date date)
      明年第一天的日期
      参数:
      date - 日期
      返回:
      Date
    • getNextYearFirst

      public static Date getNextYearFirst(String date)
    • getNextYearFirst

      public static Date getNextYearFirst()
    • countDaysOfYear

      public static int countDaysOfYear(Date date)
      一年多少天
      参数:
      date - date
      返回:
      int
    • countDaysOfYear

      public static int countDaysOfYear(int year)
    • countDaysOfYear

      public static int countDaysOfYear()
    • countDaysOfMonth

      public static int countDaysOfMonth(Date date)
      一年多少天
      参数:
      date - date
      返回:
      int
    • countDaysOfMonth

      public static int countDaysOfMonth(String ym)
    • countDaysOfMonth

      public static int countDaysOfMonth()
    • getFirstDayOfYear

      public static Date getFirstDayOfYear(Date date)
      本年第一天的日期
      参数:
      date - 日期
      返回:
      Date
    • getFirstDayOfYear

      public static Date getFirstDayOfYear(String date)
    • getFirstDayOfYear

      public static Date getFirstDayOfYear()
    • getCurrentYearEnd

      public static String getCurrentYearEnd(Date date)
      本年最后一天的日期
      参数:
      date - 日期
      返回:
      String
    • getCurrentYearEnd

      public static String getCurrentYearEnd(String date)
    • getCurrentYearEnd

      public static String getCurrentYearEnd()
    • getPreviousYearFirst

      public static String getPreviousYearFirst(Date date)
      上年第一天的日期
      参数:
      date - 日期
      返回:
      String
    • getPreviousYearFirst

      public static String getPreviousYearFirst(String date)
    • getPreviousYearFirst

      public static String getPreviousYearFirst()
    • getLastDayOfMonth

      public static int getLastDayOfMonth(int year, int month)
      获取某年某月的最后一天
      参数:
      year - 年
      month - 月
      返回:
      最后一天
    • isLeapYear

      public static boolean isLeapYear(int year)
      是否闰年
      参数:
      year - 年
      返回:
      boolean
    • parse

      public static Date parse(String date, String format) throws RuntimeException
      转换成日期
      参数:
      date - 日期
      format - format
      返回:
      Date
      抛出:
      RuntimeException
    • parse

      public static Date parse(String date, String format, Date def)
    • parse

      public static Date parse(Long value)
    • parse

      public static Date parse(Date value)
    • parse

      public static Date parse(Time value)
    • parse

      public static Date parse(LocalDate value)
    • parse

      public static Date parse(LocalDateTime value)
    • parse

      public static Date parse(ZonedDateTime value)
    • parse

      public static Date parse(LocalTime value)
    • parse

      public static Date parse(Timestamp value)
    • parse

      public static Date parse(Object value) throws RuntimeException
      抛出:
      RuntimeException
    • parse

      public static Date parse(Object value, Date def)
    • parse

      public static Date parse(String value, Date def)
    • parse

      public static Date parse(String value) throws RuntimeException
      转换成日期(使用默认格式)
      参数:
      value - 日期
      返回:
      Date
      抛出:
      RuntimeException
    • isDate

      public static boolean isDate(String str)
    • yesterday

      public static Date yesterday()
      昨天
      返回:
      Date
    • tomorrow

      public static Date tomorrow()
      明天
      返回:
      Date
    • now

      public static Date now()
      现在
      返回:
      Date
    • addDay

      public static Date addDay(int value)
      按日加
      参数:
      value - 天数
      返回:
      Date
    • addDay

      public static Date addDay(Date date, int value)
      按日加, 指定日期
      参数:
      date - 日期
      value - 天数
      返回:
      Date
    • addDay

      public static String addDay(String date, int value)
    • addMonth

      public static Date addMonth(int value)
      按月加
      参数:
      value - 月数
      返回:
      Date
    • addMonth

      public static Date addMonth(Date date, int value)
      按月加, 指定日期
      参数:
      date - 日期
      value - 月数
      返回:
      Date
    • addMonth

      public static Date addMonth(String date, int value)
    • addYear

      public static Date addYear(int value)
      按年加
      参数:
      value - 年数
      返回:
      Date
    • getDateOfWeek

      public static Date getDateOfWeek(int idx, Date date)
      当前日期所在周的第idx天 第1天:星期日 第7天:星期六
      参数:
      idx - idx
      date - 日期
      返回:
      Date
    • getDateOfWeek

      public static Date getDateOfWeek(int idx)
    • getDayOfWeek

      public static int getDayOfWeek(Date date)
      星期几(礼拜几)
      参数:
      date - date
      返回:
      int
    • getDayOfWeek

      public static int getDayOfWeek()
    • getDayOfWeek

      public static int getDayOfWeek(String date)
    • getDays

      public static List<Date> getDays(Date fr, Date to)
      区间日期
      参数:
      fr - fr
      to - to
      返回:
      List
    • getMonths

      public static List<String> getMonths(String fr, String to)
      期间的月份
      参数:
      fr - yyyy-MM 或 yyyy-MM-dd
      to - yyyy-MM 或 yyyy-MM-dd
      返回:
      List
    • getDaysOfYear

      public static List<Date> getDaysOfYear(int year)
    • getDaysOfYear

      public static List<Date> getDaysOfYear(String year)
    • getDaysOfYear

      public static List<Date> getDaysOfYear(Date date)
    • getDaysOfMonth

      public static List<Date> getDaysOfMonth(String ym)
    • getDaysOfMonth

      public static List<Date> getDaysOfMonth(Date ym)
    • getDaysOfWeek

      public static List<Date> getDaysOfWeek(int year, int week)
    • getDaysOfWeek

      public static List<Date> getDaysOfWeek(String date)
    • getDaysOfWeek

      public static List<Date> getDaysOfWeek(Date date)
    • getDays

      public static List<String> getDays(String fr, String to)
    • max

      public static String max(String... dates)
    • min

      public static String min(String... dates)
    • max

      public static Date max(Date... dates)
    • min

      public static Date min(Date... dates)
    • getWeekOfYear

      public static int getWeekOfYear(Date date)
      一年中的第几个星期
      参数:
      date - date
      返回:
      int
    • getWeekOfYear

      public static int getWeekOfYear()
    • addYear

      public static Date addYear(Date date, int value)
      按年加, 指定日期
      参数:
      date - 日期
      value - value
      返回:
      Date
    • addYear

      public static Date addYear(String date, int value)
    • addHour

      public static Date addHour(int value)
      按小时加
      参数:
      value - value
      返回:
      Date
    • addHour

      public static Date addHour(Date date, int value)
      按小时加, 指定日期
      参数:
      date - 日期
      value - value
      返回:
      Date
    • addHour

      public static Date addHour(String date, int value)
    • addMinute

      public static Date addMinute(int value)
      按分钟加
      参数:
      value - value
      返回:
      Date
    • addSecond

      public static Date addSecond(int value)
      按秒加
      参数:
      value - value
      返回:
      Date
    • addMinute

      public static Date addMinute(Date date, int value)
      按分钟加, 指定日期
      参数:
      date - 日期
      value - value
      返回:
      Date
    • addSecond

      public static Date addSecond(Date date, int value)
      按秒加, 指定日期
      参数:
      date - 日期
      value - value
      返回:
      Date
    • addMinute

      public static Date addMinute(String date, int value)
    • year

      public static int year(Date date)
      年份
      参数:
      date - date
      返回:
      int
    • year

      public static int year()
    • year

      public static int year(String date)
    • month

      public static int month(Date date)
      月份
      参数:
      date - date
      返回:
      int
    • month

      public static int month(String date)
    • month

      public static int month()
    • dayOfWeek

      public static int dayOfWeek(Date date)
      星期几(星期日=0 星期一=1)
      参数:
      date - date
      返回:
      int
    • dayOfWeek

      public static int dayOfWeek()
    • dayOfWeek

      public static int dayOfWeek(String date)
    • dayOfMonth

      public static int dayOfMonth(Date date)
      日(号)
      参数:
      date - date
      返回:
      int
    • dayOfMonth

      public static int dayOfMonth(String date)
    • dayOfMonth

      public static int dayOfMonth()
    • getDayOfMonth

      public static int getDayOfMonth(Date date)
    • getDayOfMonth

      public static int getDayOfMonth(String date)
    • getDayOfMonth

      public static int getDayOfMonth()
    • day

      public static int day(Date date)
    • day

      public static int day()
    • dayOfYear

      public static int dayOfYear(Date date)
    • dayOfYear

      public static int dayOfYear(String date)
    • dayOfYear

      public static int dayOfYear()
    • getDayOfYear

      public static int getDayOfYear(Date date)
    • getDayOfYear

      public static int getDayOfYear(String date)
    • getDayOfYear

      public static int getDayOfYear()
    • hour

      public static int hour(Date date)
      小时(点)
      参数:
      date - date
      返回:
      int
    • hour

      public static int hour()
    • minute

      public static int minute(Date date)
      分钟
      参数:
      date - date
      返回:
      int
    • minute

      public static int minute()
    • second

      public static int second(Date date)
      参数:
      date - date
      返回:
      int
    • second

      public static int second()
    • compare

      public static int compare(Date date1, Date date2)
      date1 大于 date2返回 1
      参数:
      date1 - date2
      date2 - date2
      返回:
      int
    • compare

      public static int compare(String fr, String to)
    • isAm

      public static boolean isAm(Date date)
      是上午吗?
      参数:
      date - date
      返回:
      boolean
    • isAm

      public static boolean isAm()
    • isPm

      public static boolean isPm(Date date)
      是下午吗?
      参数:
      date - date
      返回:
      boolean
    • isPm

      public static boolean isPm()
    • conversion

      public static String conversion(double src)
    • conversion

      public static String conversion(long src)
      毫秒转换成*天*时*分*秒*毫秒
      参数:
      src - 毫秒
      返回:
      String
    • localDateTime

      public static LocalDateTime localDateTime(Date date, ZoneId zone)
    • offsetDateTime

      public static OffsetDateTime offsetDateTime(Date date)
    • localDateTime

      public static LocalDateTime localDateTime(Date date)
    • zonedDateTime

      public static ZonedDateTime zonedDateTime(Date date)
    • localTime

      public static LocalTime localTime(Date date, ZoneId zone)
    • localTime

      public static LocalTime localTime(Date date)
    • localDate

      public static LocalDate localDate(Date date, ZoneId zone)
    • localDate

      public static LocalDate localDate(Date date)
    • localDateTime

      public static LocalDateTime localDateTime(Long timestamp, ZoneId zone)
    • localDateTime

      public static LocalDateTime localDateTime(Long timestamp)
    • localTime

      public static LocalTime localTime(Long timestamp, ZoneId zone)
    • localTime

      public static LocalTime localTime(Long timestamp)
    • localDate

      public static LocalDate localDate(Long timestamp, ZoneId zone)
    • localDate

      public static LocalDate localDate(Long timestamp)
    • sqlDate

      public static Date sqlDate(Date date)
    • sqlDate

      public static Date sqlDate(Timestamp date)
    • sqlTime

      public static Time sqlTime(Date date)
    • sqlTimestamp

      public static Timestamp sqlTimestamp(Date date)
    • sqlDate

      public static Date sqlDate(LocalDate date)
    • yearMonth

      public static YearMonth yearMonth(Date date)