类 DateUtils

    • 字段详细资料

      • DEFAULT_TIMESTAMP_PATTERN

        public static final String DEFAULT_TIMESTAMP_PATTERN
        另请参阅:
        常量字段值
      • DATE_TIME

        public static final long DATE_TIME
        另请参阅:
        常量字段值
      • DATE_TIME_SECOND

        public static final long DATE_TIME_SECOND
        另请参阅:
        常量字段值
      • HOUR_TIME

        public static final long HOUR_TIME
        另请参阅:
        常量字段值
      • MINUTE_TIME

        public static final long MINUTE_TIME
        另请参阅:
        常量字段值
      • SECOND_TIME

        public static final long SECOND_TIME
        另请参阅:
        常量字段值
      • TIME_ZONE

        public static final long TIME_ZONE
      • TIME_ZONE_STRING

        public static final String TIME_ZONE_STRING
      • TEN_MINUTE_TIME

        public static final long TEN_MINUTE_TIME
        另请参阅:
        常量字段值
    • 构造器详细资料

      • DateUtils

        public DateUtils()
    • 方法详细资料

      • minutesToMillis

        public static long minutesToMillis​(long minutes)
        Converts minutes to millis
        参数:
        minutes - time in minutes
        返回:
        corresponding millis value
      • secondsToMillis

        public static long secondsToMillis​(long seconds)
        Converts seconds to millis
        参数:
        seconds - time in seconds
        返回:
        corresponding millis value
      • millisToMinutes

        public static long millisToMinutes​(long millis)
        Converts millis to minutes
        参数:
        millis - time in millis
        返回:
        time in minutes
      • millisToSeconds

        public static long millisToSeconds​(long millis)
        Converts millis to seconds
        参数:
        millis - time in millis
        返回:
        time in seconds
      • timeAfterMillis

        public static long timeAfterMillis​(long millis)
        Returns timestamp in the future after some millis passed from now
        参数:
        millis - millis count
        返回:
        future timestamp
      • toGMTString

        public static String toGMTString​(Date date)
      • convertDate

        public static String convertDate​(Date date)
        把日期转换成yyyy-MM-dd HH:mm:ss格式
        参数:
        date -
        返回:
        String
      • convertDate

        public static String convertDate​(Date date,
                                         String pattern)
        把日期转换成pattern格式
        参数:
        date -
        pattern -
        返回:
        String
      • convertStringToDate

        public static Date convertStringToDate​(String date)
        参数:
        date -
        返回:
        Date
      • convertStringToDate

        public static Date convertStringToDate​(String date,
                                               String pattern)
        参数:
        date -
        pattern -
        返回:
        Date
      • isFirstDayInMonth

        public static boolean isFirstDayInMonth​(Date date)
        判断传入的日期是不是当月的第一天
        参数:
        date -
        返回:
        boolean
      • isFirstDayInYear

        public static boolean isFirstDayInYear​(Date date)
        判断传入的日期是不是当年的第一天
        参数:
        date -
        返回:
        boolean
      • rounding

        public static Date rounding​(Date date)
        去掉时分秒后返回
        参数:
        date -
        返回:
        Date
      • dateAdd

        public static Date dateAdd​(Date date,
                                   int day)
        把时间加上day天后返回,如果传负数代表减day天
        参数:
        date -
        day -
        返回:
        Date
      • dateAddMonth

        public static Date dateAddMonth​(Date date,
                                        int month)
        多少个月前后的今天
        参数:
        date -
        month -
        返回:
        Date
      • getFirstDayOfPreviousMonth

        public static Date getFirstDayOfPreviousMonth()
        获取上一个月的第一天
        返回:
        Date
      • getFirstDayOfMonth

        public static Date getFirstDayOfMonth()
        获取本月的第一天
        返回:
        Date
      • getFirstDayOfMonth

        public static Date getFirstDayOfMonth​(Date date)
        获取本月的第一天
        参数:
        date -
        返回:
        Date
      • getFirstDayOfPreviousYear

        public static Date getFirstDayOfPreviousYear()
        获取上一年的第一天
        返回:
        Date
      • getDateRange

        public static List<String> getDateRange​(String beginDate,
                                                String endDate,
                                                int type)
        获取两个时间段之间相差日期列表
        参数:
        beginDate - 开始时间
        endDate - 结束时间
        type - 1表示获取两个时间之间相差的“月份-日期”列表,2表示两个时间之间相差的“年份-月份”列表
        返回:
        两个时间段之间相差的时间列表
      • isEmpty

        public static boolean isEmpty​(Object obj)
        判断对象是否为空
        参数:
        obj - 对象
        返回:
        如果为空返回true,否则返回false
      • getWeekDay

        public static String getWeekDay​(Calendar c)
        获取星期几
        参数:
        c -
        返回:
        String
      • convertLebalFull

        public static String convertLebalFull​(Date startTime,
                                              Date endTime,
                                              boolean showSuffix)
        时间标签 返回两个时间的间隔
        参数:
        startTime - 开始时间
        endTime - 结束时间
        showSuffix - 是否添加“前”/“后”标签
        返回:
        String
      • convertLebal

        public static String convertLebal​(Date startTime,
                                          Date endTime,
                                          boolean showSuffix)
        时间标签 返回两个时间的间隔
        参数:
        startTime - 开始时间
        endTime - 结束时间
        showSuffix - 是否添加“前”/“后”标签
        返回:
        String 返回的时间标签
      • analyzeTime

        public static String analyzeTime​(long time,
                                         boolean showFull)
        把时间戳转为指定显示格式
        参数:
        time - 时间
        showFull - 是否全显示
        返回:
        时间的显示字符串
      • getToday

        public static Date getToday()
        获取当前时间的日期
        返回:
        日期
      • getYesterday

        public static Date getYesterday()
        获取昨天的日期
        返回:
        日期
      • getBetweenDateDays

        public static int getBetweenDateDays​(Date startTime,
                                             Date endTime)
        获取两个日期之间的间隔天数
        参数:
        startTime -
        endTime -
        返回:
        int
      • getTomorrow

        public static Date getTomorrow()
        获取明天的日期
        返回:
        日期
      • checkAfterTime

        public static boolean checkAfterTime​(Date date,
                                             String time)
        检查传入的时间是否在当前时间小时数之后
        参数:
        date -
        time -
        返回:
        boolean
      • getOffsetStringDate

        public static String getOffsetStringDate​(long offsetTime)
        将一个时间戳,根据其大小转换为对应的‘时分秒毫秒’不同组合的字符串
        参数:
        offsetTime - 时间
        返回:
        时分秒组合的字符串
      • dateAddHours

        public static Date dateAddHours​(Date startDate,
                                        int hours)
        时间加减小时
        参数:
        startDate - 要处理的时间,Null则为当前时间
        hours - 加减的小时
        返回:
        Date
      • dateAddMinutes

        public static Date dateAddMinutes​(Date startDate,
                                          int minutes)
        时间加减分钟
        参数:
        startDate - 要处理的时间,Null则为当前时间
        minutes - 加减的分钟
        返回:
      • dateAddSeconds

        public static Date dateAddSeconds​(Date startDate,
                                          int seconds)
        时间加减秒数
        参数:
        startDate - 要处理的时间,Null则为当前时间
        seconds - 加减的秒数
        返回:
      • dateAddDays

        public static Date dateAddDays​(Date startDate,
                                       int days)
        时间加减天数
        参数:
        startDate - 要处理的时间,Null则为当前时间
        days - 加减的天数
        返回:
        Date
      • dateAddMonths

        public static Date dateAddMonths​(Date startDate,
                                         int months)
        时间加减月数
        参数:
        startDate - 要处理的时间,Null则为当前时间
        months - 加减的月数
        返回:
        Date
      • dateAddYears

        public static Date dateAddYears​(Date startDate,
                                        int years)
        时间加减年数
        参数:
        startDate - 要处理的时间,Null则为当前时间
        years - 加减的年数
        返回:
        Date
      • dateCompare

        public static int dateCompare​(Date myDate,
                                      Date compareDate)
        时间比较(如果myDate>compareDate返回1,<返回-1,相等返回0)
        参数:
        myDate - 时间
        compareDate - 要比较的时间
        返回:
        int
      • dateMin

        public static Date dateMin​(Date date,
                                   Date compareDate)
        获取两个时间中最小的一个时间
        参数:
        date - 被比较时间
        compareDate - 比较时间
        返回:
        结果
      • dateMax

        public static Date dateMax​(Date date,
                                   Date compareDate)
        获取两个时间中最大的一个时间
        参数:
        date - 被比较时间
        compareDate - 比较时间
        返回:
        结果
      • getYear

        public static int getYear​(Date date)
        获取日期时间的年份,如2017-02-13,返回2017
        参数:
        date -
        返回:
      • getMonth

        public static int getMonth​(Date date)
        获取日期时间的月份,如2017年2月13日,返回2
        参数:
        date -
        返回:
      • getDate

        public static int getDate​(Date date)
        获取日期时间的第几天(即返回日期的dd),如2017-02-13,返回13
        参数:
        date -
        返回:
      • timeStamp2DateStr

        public static String timeStamp2DateStr​(long time)
        时间戳转换成日期默认格式字符串
        参数:
        time - 时间戳
        返回:
        日期格式字符串
      • timeStamp2Str

        public static String timeStamp2Str​(long time)
        时间戳转换成日期默认格式字符串
        参数:
        time - 时间戳
        返回:
        日期格式字符串
      • timeStamp2DateStr

        public static String timeStamp2DateStr​(long time,
                                               String format)
        时间戳转换成日期格式字符串
        参数:
        time - 时间戳
        format - 日期字符串格式
        返回:
        日期字符串
      • timeStamp2DateStr

        public static String timeStamp2DateStr​(long time,
                                               String format,
                                               Locale locale)
        时间戳转换成日期格式字符串
        参数:
        time - 时间戳
        format - 日期字符串格式
        返回:
        日期字符串
      • isSameDay

        public static boolean isSameDay​(long time1,
                                        long time2)
        时间戳转换成日期格式字符串
        参数:
        time1 - 时间戳1(毫秒)
        time2 - 时间戳2(毫秒)
        返回:
        日期字符串
      • isSameDayBySecond

        public static boolean isSameDayBySecond​(long time1,
                                                long time2)
        比较两个时间是否为同一天
        参数:
        time1 - 时间戳1(秒)
        time2 - 时间戳2(秒)
        返回:
        日期字符串
      • getTimeZone

        public static long getTimeZone()
        获取时区信息
      • getTimeZoneString

        public static String getTimeZoneString()
        获取时区信息