程序包 cn.godmao.utils

类 DateUtil

java.lang.Object
cn.hutool.core.date.CalendarUtil
cn.hutool.core.date.DateUtil
cn.godmao.utils.DateUtil

public class DateUtil extends cn.hutool.core.date.DateUtil
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    static final String
    时间格式
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static Date
    addDateDays(Date date, int days)
    对日期的【天】进行加/减
    static Date
    addDateHours(Date date, int hours)
    对日期的【小时】进行加/减
    static Date
    addDateMinutes(Date date, int minutes)
    对日期的【分钟】进行加/减
    static Date
    addDateMonths(Date date, int months)
    对日期的【月】进行加/减
    static Date
    addDateSeconds(Date date, int seconds)
    对日期的【秒】进行加/减
    static Date
    addDateWeeks(Date date, int weeks)
    对日期的【周】进行加/减
    static Date
    addDateYears(Date date, int years)
    对日期的【年】进行加/减
    static List<String>
    补齐时间区间
    static int
    计算与当前时间差值
    static Date
    designatedDate(int day)
    计算指定天数的日期
    static String
    formartLocalDate(LocalDate localDate, String pattern)
    LocalDate 类型的日期格式化为指定格式的字符串
    static String
    format(Date date, String pattern)
    日期格式化为指定格式的字符串
    static String
    formatLocalDateTime(LocalDateTime localDateTime, String pattern)
    LocalDateTime 类型的时间格式化为指定格式的字符串
    fromMillSeconds(long millSeconds)
    从毫秒数拿到 LocalDateTime
    fromSeconds(long seconds)
    从秒数拿到 LocalDateTime
    static long
    从 LocalDateTime 拿到毫秒数
    static String[]
    获取所有时间格式
    static long
    getSeconds(LocalDateTime localDateTime)
    从 LocalDateTime 拿到秒数
    static boolean
    isToday(long time)
    判断某一时间时间是不是今天
    static Date
    上周周一零点
    static Date
    去年1月1日零点
    static Date
    本周周一零点
    static Date
    万能转换 "2020-11-05"...
    static Date
    toDate(String str, String pattern)
    字符串转成 Date 类型
    static Date
    toDate(LocalDate localDate)
    LocalDate 转成 Date
    static Date
    toDate(LocalDateTime localDateTime)
    LocalDateTime 转成 Date
    static LocalDate
    字符串转成 LocalDate 类型的日期 默认 str 形如 "yyyy-MM-dd"
    static LocalDate
    toLocalDate(String str, String pattern)
    字符串转成 LocalDate 类型的日期
    static LocalDate
    Date 类型日期转成 LocalDate 类型的日期
    字符串类型的时间转成 LocalDateTime 类型的时间,默认形如 "yyyy-MM-dd HH:mm:ss"
    toLocalDateTime(String str, String pattern)
    字符串类型的时间转成 LocalDateTime 类型的时间
    LocalDate 时间转成 LocalDateTime 类型时间为当天开始时间
    Date 类型的时间转成 LocalDateTime 类型的时间
    从 Date 获取特定时区的时间
    static Date
    weekEnd(Integer plusWeeks)
    周日23:59:59.999 plusWeeks 0是这周 1是下周 以此类推
    static Date
    weekStart(Integer plusWeeks)
    周一00:00:00:000 plusWeeks 0是这周 1是下周 以此类推
    static Date
    今年1月1日零点

    从类继承的方法 cn.hutool.core.date.DateUtil

    age, ageOfNow, ageOfNow, beginOfDay, beginOfHour, beginOfMinute, beginOfMonth, beginOfQuarter, beginOfSecond, beginOfWeek, beginOfWeek, beginOfYear, between, between, betweenDay, betweenMonth, betweenMs, betweenWeek, betweenYear, ceiling, ceiling, compare, compare, convertTimeZone, convertTimeZone, createStopWatch, createStopWatch, current, currentSeconds, date, date, date, date, date, dateNew, dateSecond, dayOfMonth, dayOfWeek, dayOfWeekEnum, dayOfYear, endOfDay, endOfHour, endOfMinute, endOfMonth, endOfQuarter, endOfSecond, endOfWeek, endOfWeek, endOfYear, format, format, format, format, formatBetween, formatBetween, formatBetween, formatBetween, formatChineseDate, formatDate, formatDateTime, formatHttpDate, formatLocalDateTime, formatTime, getChineseZodiac, getLastDayOfMonth, getShotName, getZodiac, hour, isAM, isExpired, isExpired, isIn, isLastDayOfMonth, isLeapYear, isOverlap, isPM, isSameDay, isSameMonth, isSameTime, isSameWeek, isWeekend, lastMonth, lastWeek, lengthOfMonth, lengthOfYear, millisecond, minute, month, monthEnum, nanosToMillis, nanosToSeconds, newSimpleFormat, newSimpleFormat, nextMonth, nextWeek, now, offset, offsetDay, offsetHour, offsetMillisecond, offsetMinute, offsetMonth, offsetSecond, offsetWeek, parse, parse, parse, parse, parse, parse, parse, parse, parseCST, parseDate, parseDateTime, parseLocalDateTime, parseLocalDateTime, parseTime, parseTimeToday, parseUTC, quarter, quarterEnum, range, rangeConsume, rangeContains, rangeFunc, rangeNotContains, rangeToList, rangeToList, round, second, secondToTime, spendMs, spendNt, thisDayOfMonth, thisDayOfWeek, thisDayOfWeekEnum, thisHour, thisMillisecond, thisMinute, thisMonth, thisMonthEnum, thisSecond, thisWeekOfMonth, thisWeekOfYear, thisYear, timer, timer, timeToSecond, today, toInstant, toInstant, toIntSecond, toLocalDateTime, tomorrow, truncate, weekOfMonth, weekOfYear, year, yearAndQuarter, yearAndQuarter, yesterday

    从类继承的方法 cn.hutool.core.date.CalendarUtil

    age, age, beginOfDay, beginOfHour, beginOfMinute, beginOfMonth, beginOfQuarter, beginOfSecond, beginOfWeek, beginOfWeek, beginOfYear, calendar, calendar, calendar, calendar, ceiling, ceiling, compare, endOfDay, endOfHour, endOfMinute, endOfMonth, endOfQuarter, endOfSecond, endOfWeek, endOfWeek, endOfYear, formatChineseDate, getBeginValue, getBeginValue, getEndValue, getEndValue, isAM, isPM, isSameDay, isSameInstant, isSameMonth, isSameWeek, parse, parseByPatterns, parseByPatterns, parseByPatterns, round, toInstant, toLocalDateTime, truncate, yearAndQuarter, yearAndQuarter

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

  • 构造器详细资料

    • DateUtil

      public DateUtil()
  • 方法详细资料

    • format

      public static String format(Date date, String pattern)
      日期格式化为指定格式的字符串
      参数:
      date - 日期
      pattern - 格式,如:DateUtils.DATE_PATTERN
      返回:
      返回指定格式字符串时间
    • formartLocalDate

      public static String formartLocalDate(LocalDate localDate, String pattern)
      LocalDate 类型的日期格式化为指定格式的字符串
      参数:
      localDate - LocalDate 类型的日期
      pattern - 格式,如:DateUtils.DATE_PATTERN
      返回:
      返回指定格式字符串时间
    • formatLocalDateTime

      public static String formatLocalDateTime(LocalDateTime localDateTime, String pattern)
      LocalDateTime 类型的时间格式化为指定格式的字符串
      参数:
      localDateTime - LocalDateTime 类型的时间
      pattern - 格式,如 DateUtils.DATE_PATTERN
      返回:
      指定格式字符串时间
    • toDate

      public static Date toDate(String str, String pattern)
      字符串转成 Date 类型
      参数:
      str - 日期字符串
      pattern - 日期的格式:如:DateUtils.DATE_PATTERN
      返回:
      Date 类型的时间
    • toDate

      public static Date toDate(LocalDate localDate)
      LocalDate 转成 Date
      参数:
      localDate - LocalDate 类型日期
      返回:
      Date 类型的日期
    • toDate

      public static Date toDate(LocalDateTime localDateTime)
      LocalDateTime 转成 Date
      参数:
      localDateTime - LocalDateTime 类型时间
      返回:
      Date 类型的时间
    • toLocalDate

      public static LocalDate toLocalDate(String str)
      字符串转成 LocalDate 类型的日期 默认 str 形如 "yyyy-MM-dd"
      参数:
      str - 字符串日期
      返回:
      LocalDate 类型的日期
    • toLocalDate

      public static LocalDate toLocalDate(String str, String pattern)
      字符串转成 LocalDate 类型的日期
      参数:
      str - 字符串日期
      pattern - 字符串格式,如 DateUtils.DATE_PATTERN
      返回:
      LocalDate 类型的日期
    • toLocalDate

      public static LocalDate toLocalDate(Date date)
      Date 类型日期转成 LocalDate 类型的日期
      参数:
      date - Date 类型的日期
      返回:
      LocalDate 类型的日期
    • toLocalDateTime

      public static LocalDateTime toLocalDateTime(String str)
      字符串类型的时间转成 LocalDateTime 类型的时间,默认形如 "yyyy-MM-dd HH:mm:ss"
      参数:
      str - 字符串时间,默认形如 "yyyy-MM-dd HH:mm:ss"
      返回:
      LocalDateTime 类型的时间
    • toLocalDateTime

      public static LocalDateTime toLocalDateTime(String str, String pattern)
      字符串类型的时间转成 LocalDateTime 类型的时间
      参数:
      str - 字符串时间
      pattern - 字符串时间格式
      返回:
      LocalDateTime 类型的时间
    • toLocalDateTime

      public static LocalDateTime toLocalDateTime(Date date)
      Date 类型的时间转成 LocalDateTime 类型的时间
      参数:
      date - Date 类型的时间
      返回:
      LocalDateTime 类型的时间
    • toLocalDateTime

      public static LocalDateTime toLocalDateTime(LocalDate localDate)
      LocalDate 时间转成 LocalDateTime 类型时间为当天开始时间
      参数:
      localDate - LocalDate 类型的时间
      返回:
      LocalDateTime 类型时间为当天开始时间
    • addDateSeconds

      public static Date addDateSeconds(Date date, int seconds)
      对日期的【秒】进行加/减
      参数:
      date - 日期
      seconds - 秒数,负数为减
      返回:
      加/减几秒后的日期
    • addDateMinutes

      public static Date addDateMinutes(Date date, int minutes)
      对日期的【分钟】进行加/减
      参数:
      date - 日期
      minutes - 分钟数,负数为减
      返回:
      加/减几分钟后的日期
    • addDateHours

      public static Date addDateHours(Date date, int hours)
      对日期的【小时】进行加/减
      参数:
      date - 日期
      hours - 小时数,负数为减
      返回:
      加/减几小时后的日期
    • addDateDays

      public static Date addDateDays(Date date, int days)
      对日期的【天】进行加/减
      参数:
      date - 日期
      days - 天数,负数为减
      返回:
      加/减几天后的日期
    • addDateWeeks

      public static Date addDateWeeks(Date date, int weeks)
      对日期的【周】进行加/减
      参数:
      date - 日期
      weeks - 周数,负数为减
      返回:
      加/减几周后的日期
    • addDateMonths

      public static Date addDateMonths(Date date, int months)
      对日期的【月】进行加/减
      参数:
      date - 日期
      months - 月数,负数为减
      返回:
      加/减几月后的日期
    • addDateYears

      public static Date addDateYears(Date date, int years)
      对日期的【年】进行加/减
      参数:
      date - 日期
      years - 年数,负数为减
      返回:
      加/减几年后的日期
    • toZonedDateTime

      public static ZonedDateTime toZonedDateTime(Date date)
      从 Date 获取特定时区的时间
      参数:
      date - Date 类型的时间
      返回:
      DateUtils.DEFAULT_ZONE_ID 标定的时区时间
    • fromSeconds

      public static LocalDateTime fromSeconds(long seconds)
      从秒数拿到 LocalDateTime
      参数:
      seconds - 秒数
      返回:
      localDateTime
    • fromMillSeconds

      public static LocalDateTime fromMillSeconds(long millSeconds)
      从毫秒数拿到 LocalDateTime
      参数:
      millSeconds - 毫秒数
      返回:
      localDateTime
    • getSeconds

      public static long getSeconds(LocalDateTime localDateTime)
      从 LocalDateTime 拿到秒数
      参数:
      localDateTime - localDateTime
      返回:
      秒数
    • getMillSeconds

      public static long getMillSeconds(LocalDateTime localDateTime)
      从 LocalDateTime 拿到毫秒数
      参数:
      localDateTime - localDateTime
      返回:
      毫秒数
    • getPatterns

      public static String[] getPatterns()
      获取所有时间格式
    • parseDate

      public static Date parseDate(Object str)
      万能转换 "2020-11-05"...
      参数:
      str -
      返回:
    • lastMonday

      public static Date lastMonday()
      上周周一零点
    • monday

      public static Date monday()
      本周周一零点
    • weekStart

      public static Date weekStart(Integer plusWeeks)
      周一00:00:00:000 plusWeeks 0是这周 1是下周 以此类推
      返回:
    • weekEnd

      public static Date weekEnd(Integer plusWeeks)
      周日23:59:59.999 plusWeeks 0是这周 1是下周 以此类推
      返回:
    • lastYear

      public static Date lastYear()
      去年1月1日零点
    • year

      public static Date year()
      今年1月1日零点
    • designatedDate

      public static Date designatedDate(int day)
      计算指定天数的日期
    • dateDelta

      public static int dateDelta(Date date)
      计算与当前时间差值
    • completionDate

      public static List<String> completionDate(LocalDateTime startDate, LocalDateTime endDate)
      补齐时间区间
    • isToday

      public static boolean isToday(long time)
      判断某一时间时间是不是今天
      参数:
      time -
      返回: