类 DateUtils


  • public class DateUtils
    extends cn.hutool.core.date.DateUtil
    时间工具类(JDK1.8)
    从以下版本开始:
    2017年10月25日(JDK1.8)
    作者:
    ylyue
    • 字段详细资料

      • DATE_TIME_FORMAT

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

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

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

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

        年-月-日

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

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

        时:分:秒

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

        public static final DateTimeFormatter DATE_TIME_FORMATTER
        DateTime 格式化

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

      • DATE_FORMATTER

        public static final DateTimeFormatter DATE_FORMATTER
        Date 格式化

        年-月-日

      • TIME_FORMATTER

        public static final DateTimeFormatter TIME_FORMATTER
        Time 格式化

        时:分:秒

      • DATE_TIME_KEEP_MS_FORMATTER

        public static final DateTimeFormatter DATE_TIME_KEEP_MS_FORMATTER
        DateTime 保留毫秒格式化

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

      • TODAY_START_FORMATTER

        public static final DateTimeFormatter TODAY_START_FORMATTER
        当天起始时间

        年-月-日 00:00:00

      • TODAY_END_FORMATTER

        public static final DateTimeFormatter TODAY_END_FORMATTER
        当天结束时间

        年-月-日 23:59:59

      • MONTH_START_FORMATTER

        public static final DateTimeFormatter MONTH_START_FORMATTER
        当月起始时间

        年-月-01 00:00:00

    • 构造器详细资料

      • DateUtils

        public DateUtils()
    • 方法详细资料

      • isBetween

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

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

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

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

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

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

        public static long getTimestamp()
        获得当前时间戳
        返回:
        当前时间戳
      • getTimestamp

        public static long getTimestamp​(int offsetMillis)
        获得当前时间偏移后的时间戳
        参数:
        offsetMillis - 偏移毫秒
        返回:
        当前时间偏移后的时间戳
      • getDateFormatter

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

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

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

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

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

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

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

        public static LocalDateTime toLocalDateTime​(Date date)
        DateLocalDateTime

        默认使用系统时区转换

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

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

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

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

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

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

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

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