类 DateUtils


  • public class DateUtils
    extends cn.hutool.core.date.DateUtil
    时间工具类(JDK1.8)
    从以下版本开始:
    2017年10月25日(JDK1.8)
    作者:
    ylyue
    • 构造器概要

      构造器 
      构造器 说明
      DateUtils()  
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static long dateDaysDifference​(java.time.LocalDate startDate, java.time.LocalDate endDate)
      计算日期相差天数
      static long dateDaysDifference​(java.time.LocalDateTime startTime, java.time.LocalDateTime endTime)
      计算日期相差天数
      static java.lang.String getDateFormatter()
      获得当前日期的标准字符串格式
      static java.lang.String getDatetimeFormatter()
      获得当前日期时间的标准字符串格式
      static java.lang.Long getTimestamp()
      获得当前时间戳
      static java.lang.String getTodayEndFormatter()
      获得当天结束时间的标准字符串格式
      static java.lang.String getTodayStartFormatter()
      获得当天起始时间的标准字符串格式
      static java.lang.String getWeekmorningFormatter()
      获得本周开始时间的标准字符串格式
      static java.lang.String getWeeknight()
      获得本周日结束时间的标准字符串格式
      static boolean isBetween​(java.lang.String startTime, java.lang.String dateTime, java.lang.String endTime)
      判断某个时间是否在某个时间段
      static boolean isBetween​(java.time.LocalDateTime startTime, java.time.LocalDateTime dateTime, java.time.LocalDateTime endTime)
      判断某个时间是否在某个时间段
      static boolean isBetween​(java.util.Date startTime, java.util.Date dateTime, java.util.Date endTime)
      判断某个时间是否在某个时间段
      static java.lang.String to_y_M_d_H_m_s​(java.time.temporal.TemporalAccessor date)
      TemporalAccessor 类型进行标准日期时间字符串格式化
      static java.lang.String toDateFormatter​(long timestamp)
      将毫秒时间(时间戳)转化为标准日期字符串格式
      static java.lang.String toDateFormatter​(java.time.temporal.TemporalAccessor date)
      TemporalAccessor 类型进行标准日期字符串格式化
      static java.lang.String toDateFormatter​(java.util.Date date)
      Date 类型进行标准日期字符串格式化
      static java.lang.String toDateTimeFormatter​(long timestamp)
      将毫秒时间(时间戳)转化为标准日期时间字符串格式
      static java.lang.String toDateTimeFormatter​(java.util.Date date)
      Date 类型进行标准日期时间字符串格式化
      static java.time.LocalDateTime toLocalDateTime​(java.util.Date date)
      将 Date 转 LocalDateTime
      static java.lang.Long toTimestamp​(java.lang.String dateTime)
      将日期时间转换成时间戳
      • 从类继承的方法 cn.hutool.core.date.DateUtil

        age, ageOfNow, ageOfNow, beginOfDay, beginOfDay, beginOfMonth, beginOfMonth, beginOfQuarter, beginOfQuarter, beginOfSecond, beginOfSecond, beginOfWeek, beginOfWeek, beginOfWeek, beginOfYear, beginOfYear, between, between, betweenDay, betweenMonth, betweenMs, betweenWeek, betweenYear, calendar, calendar, calendar, ceiling, ceiling, compare, compare, createStopWatch, createStopWatch, current, currentSeconds, date, date, date, date, date, dateNew, dateSecond, dayOfMonth, dayOfWeek, dayOfWeekEnum, endOfDay, endOfDay, endOfMonth, endOfMonth, endOfQuarter, endOfQuarter, endOfSecond, endOfSecond, endOfWeek, endOfWeek, endOfWeek, endOfYear, endOfYear, format, format, format, format, format, formatBetween, formatBetween, formatBetween, formatBetween, formatChineseDate, formatDate, formatDateTime, formatHttpDate, formatLocalDateTime, formatTime, getBeginValue, getChineseZodiac, getEndValue, getZodiac, hour, isAM, isAM, isExpired, isExpired, isIn, isLeapYear, isPM, isSameDay, isSameDay, isSameTime, lastMonth, lastWeek, millsecond, minute, month, monthEnum, nanosToMillis, nanosToSeconds, nextMonth, nextWeek, now, offset, offsetDate, offsetDay, offsetHour, offsetMillisecond, offsetMinute, offsetMonth, offsetSecond, offsetWeek, parse, parse, parse, parse, parse, parse, parseCST, parseDate, parseDateTime, parseLocalDateTime, parseLocalDateTime, parseTime, parseTimeToday, parseUTC, quarter, quarterEnum, range, rangeToList, round, round, second, secondToTime, spendMs, spendNt, thisDayOfMonth, thisDayOfWeek, thisDayOfWeekEnum, thisHour, thisMillsecond, thisMinute, thisMonth, thisMonthEnum, thisSecond, thisWeekOfMonth, thisWeekOfYear, thisYear, timer, timer, timeToSecond, today, toInstant, toInstant, toInstant, toIntSecond, toLocalDateTime, toLocalDateTime, tomorrow, truncate, truncate, weekCount, weekOfMonth, weekOfYear, year, yearAndQuarter, yearAndQuarter, yearAndQuarter, yesterday
      • 从类继承的方法 java.lang.Object

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

      • DATE_TIME_FORMAT

        public static final java.lang.String DATE_TIME_FORMAT
        DateTime 格式化字符串

        年-月-日 时:分:秒(标准北京时间)

        另请参阅:
        常量字段值
      • DATE_FORMAT

        public static final java.lang.String DATE_FORMAT
        Date 格式化字符串

        年-月-日

        另请参阅:
        常量字段值
      • TIME_FORMAT

        public static final java.lang.String TIME_FORMAT
        Time 格式化字符串

        时:分:秒

        另请参阅:
        常量字段值
      • DATE_TIME_FORMATTER

        public static final java.time.format.DateTimeFormatter DATE_TIME_FORMATTER
        DateTime 格式化

        年-月-日 时:分:秒(标准北京时间)

      • DATE_FORMATTER

        public static final java.time.format.DateTimeFormatter DATE_FORMATTER
        Date 格式化

        年-月-日

      • TIME_FORMATTER

        public static final java.time.format.DateTimeFormatter TIME_FORMATTER
        Time 格式化

        时:分:秒

      • FORMATTER

        public static final java.time.format.DateTimeFormatter FORMATTER
        年-月-日T时:分:秒
      • DATE_TIME_KEEP_MS_FORMATTER

        public static final java.time.format.DateTimeFormatter DATE_TIME_KEEP_MS_FORMATTER
        DateTime 保留毫秒格式化

        年-月-日 时:分:秒:毫秒

      • TODAY_START_FORMATTER

        public static final java.time.format.DateTimeFormatter TODAY_START_FORMATTER
        当天起始时间

        年-月-日 00:00:00

      • TODAY_END_FORMATTER

        public static final java.time.format.DateTimeFormatter TODAY_END_FORMATTER
        当天结束时间

        年-月-日 23:59:59

      • MONTH_START_FORMATTER

        public static final java.time.format.DateTimeFormatter MONTH_START_FORMATTER
        当月起始时间

        年-月-01 00:00:00

    • 构造器详细资料

      • DateUtils

        public DateUtils()
    • 方法详细资料

      • isBetween

        public static boolean isBetween​(java.lang.String startTime,
                                        java.lang.String dateTime,
                                        java.lang.String endTime)
        判断某个时间是否在某个时间段

        String 类型值应该是一个按照 yyyy-MM-dd HH:mm:ss 规则格式化后的字符串

        若类型不确定请使用 isBetween(LocalDateTime, LocalDateTime, LocalDateTime)

        参数:
        startTime - 起始时间
        dateTime - 比较时间
        endTime - 结束时间
        返回:
        是否在…之间
      • isBetween

        public static boolean isBetween​(java.time.LocalDateTime startTime,
                                        java.time.LocalDateTime dateTime,
                                        java.time.LocalDateTime endTime)
        判断某个时间是否在某个时间段
        参数:
        startTime - 起始时间
        dateTime - 比较时间
        endTime - 结束时间
        返回:
        是否在…之间
      • isBetween

        public static boolean isBetween​(java.util.Date startTime,
                                        java.util.Date dateTime,
                                        java.util.Date endTime)
        判断某个时间是否在某个时间段
        参数:
        startTime - 起始时间
        dateTime - 比较时间
        endTime - 结束时间
        返回:
        是否在…之间
      • getTimestamp

        public static java.lang.Long getTimestamp()
        获得当前时间戳
        返回:
        时间戳
      • getDateFormatter

        public static java.lang.String getDateFormatter()
        获得当前日期的标准字符串格式
        返回:
        年-月-日
      • getDatetimeFormatter

        public static java.lang.String getDatetimeFormatter()
        获得当前日期时间的标准字符串格式
        返回:
        年-月-日 时:分:秒(标准北京时间)
      • getTodayStartFormatter

        public static java.lang.String getTodayStartFormatter()
        获得当天起始时间的标准字符串格式
        返回:
        年-月-日 00:00:00
      • getTodayEndFormatter

        public static java.lang.String getTodayEndFormatter()
        获得当天结束时间的标准字符串格式
        返回:
        年-月-日 23:59:59
      • getWeekmorningFormatter

        public static java.lang.String getWeekmorningFormatter()
        获得本周开始时间的标准字符串格式
        返回:
        年-月-日 00:00:00
      • getWeeknight

        public static java.lang.String getWeeknight()
        获得本周日结束时间的标准字符串格式
        返回:
        年-月-日 23:59:59
      • toTimestamp

        public static java.lang.Long toTimestamp​(java.lang.String dateTime)
        将日期时间转换成时间戳
        参数:
        dateTime - 日期时间
        返回:
        时间戳
      • toLocalDateTime

        public static java.time.LocalDateTime toLocalDateTime​(java.util.Date date)
        将 Date 转 LocalDateTime

        默认使用系统时区转换

        参数:
        date - 日期
        返回:
        本地日期时间
      • toDateFormatter

        public static java.lang.String toDateFormatter​(long timestamp)
        将毫秒时间(时间戳)转化为标准日期字符串格式
        参数:
        timestamp - 毫秒(时间戳)
        返回:
        年-月-日
      • toDateFormatter

        public static java.lang.String toDateFormatter​(java.util.Date date)
        Date 类型进行标准日期字符串格式化
        参数:
        date - 日期
        返回:
        年-月-日
      • toDateFormatter

        public static java.lang.String toDateFormatter​(java.time.temporal.TemporalAccessor date)
        TemporalAccessor 类型进行标准日期字符串格式化
        参数:
        date - 日期
        返回:
        年-月-日
      • toDateTimeFormatter

        public static java.lang.String toDateTimeFormatter​(long timestamp)
        将毫秒时间(时间戳)转化为标准日期时间字符串格式
        参数:
        timestamp - 毫秒(时间戳)
        返回:
        年-月-日 时:分:秒
      • toDateTimeFormatter

        public static java.lang.String toDateTimeFormatter​(java.util.Date date)
        Date 类型进行标准日期时间字符串格式化
        参数:
        date - 日期
        返回:
        年-月-日 时:分:秒
      • to_y_M_d_H_m_s

        public static java.lang.String to_y_M_d_H_m_s​(java.time.temporal.TemporalAccessor date)
        TemporalAccessor 类型进行标准日期时间字符串格式化
        参数:
        date - 日期
        返回:
        年-月-日 时:分:秒
      • dateDaysDifference

        public static long dateDaysDifference​(java.time.LocalDateTime startTime,
                                              java.time.LocalDateTime endTime)
        计算日期相差天数
        参数:
        startTime - 开始时间
        endTime - 结束时间
        返回:
        相差天数
      • dateDaysDifference

        public static long dateDaysDifference​(java.time.LocalDate startDate,
                                              java.time.LocalDate endDate)
        计算日期相差天数
        参数:
        startDate - 开始日期
        endDate - 结束日期
        返回:
        相差天数