类 DateUtils
- java.lang.Object
-
- network.nerve.core.model.DateUtils
-
- 直接已知子类:
NulsDateUtils
public class DateUtils extends Object
-
-
字段概要
字段 修饰符和类型 字段 说明 static StringDATE_PATTERNstatic longDATE_TIMEstatic longDATE_TIME_SECONDstatic StringDEFAULT_PATTERNstatic StringDEFAULT_TIMESTAMP_PATTERNstatic StringEMPTY_SRINGstatic longHOUR_TIMEstatic longMINUTE_TIMEstatic longSECOND_TIMEstatic longTEN_MINUTE_TIMEstatic longTIME_ZONEstatic StringTIME_ZONE_STRING
-
构造器概要
构造器 构造器 说明 DateUtils()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static StringanalyzeTime(long time, boolean showFull)把时间戳转为指定显示格式static booleancheckAfterTime(Date date, String time)检查传入的时间是否在当前时间小时数之后static StringconvertDate(Date date)把日期转换成yyyy-MM-dd HH:mm:ss格式static StringconvertDate(Date date, String pattern)把日期转换成pattern格式static StringconvertLebal(Date startTime, Date endTime, boolean showSuffix)时间标签 返回两个时间的间隔static StringconvertLebalFull(Date startTime, Date endTime, boolean showSuffix)时间标签 返回两个时间的间隔static DateconvertStringToDate(String date)static DateconvertStringToDate(String date, String pattern)static DatedateAdd(Date date, int day)把时间加上day天后返回,如果传负数代表减day天static DatedateAddDays(Date startDate, int days)时间加减天数static DatedateAddHours(Date startDate, int hours)时间加减小时static DatedateAddMinutes(Date startDate, int minutes)时间加减分钟static DatedateAddMonth(Date date, int month)多少个月前后的今天static DatedateAddMonths(Date startDate, int months)时间加减月数static DatedateAddSeconds(Date startDate, int seconds)时间加减秒数static DatedateAddYears(Date startDate, int years)时间加减年数static intdateCompare(Date myDate, Date compareDate)时间比较(如果myDate>compareDate返回1,<返回-1,相等返回0)static DatedateMax(Date date, Date compareDate)获取两个时间中最大的一个时间static DatedateMin(Date date, Date compareDate)获取两个时间中最小的一个时间static intgetBetweenDateDays(Date startTime, Date endTime)获取两个日期之间的间隔天数static intgetDate(Date date)获取日期时间的第几天(即返回日期的dd),如2017-02-13,返回13static List<String>getDateRange(String beginDate, String endDate, int type)获取两个时间段之间相差日期列表static DategetFirstDayOfMonth()获取本月的第一天static DategetFirstDayOfMonth(Date date)获取本月的第一天static DategetFirstDayOfPreviousMonth()获取上一个月的第一天static DategetFirstDayOfPreviousYear()获取上一年的第一天static intgetMonth(Date date)获取日期时间的月份,如2017年2月13日,返回2static StringgetOffsetStringDate(long offsetTime)将一个时间戳,根据其大小转换为对应的‘时分秒毫秒’不同组合的字符串static longgetTimeZone()获取时区信息static StringgetTimeZoneString()获取时区信息static DategetToday()获取当前时间的日期static DategetTomorrow()获取明天的日期static StringgetWeekDay(Calendar c)获取星期几static intgetYear(Date date)获取日期时间的年份,如2017-02-13,返回2017static DategetYesterday()获取昨天的日期static booleanisEmpty(Object obj)判断对象是否为空static booleanisFirstDayInMonth(Date date)判断传入的日期是不是当月的第一天static booleanisFirstDayInYear(Date date)判断传入的日期是不是当年的第一天static booleanisSameDay(long time1, long time2)时间戳转换成日期格式字符串static booleanisSameDayBySecond(long time1, long time2)比较两个时间是否为同一天static longmillisToMinutes(long millis)Converts millis to minutesstatic longmillisToSeconds(long millis)Converts millis to secondsstatic longminutesToMillis(long minutes)Converts minutes to millisstatic Daterounding(Date date)去掉时分秒后返回static longsecondsToMillis(long seconds)Converts seconds to millisstatic longtimeAfterMillis(long millis)Returns timestamp in the future after some millis passed from nowstatic StringtimeStamp2DateStr(long time)时间戳转换成日期默认格式字符串static StringtimeStamp2DateStr(long time, String format)时间戳转换成日期格式字符串static StringtimeStamp2DateStr(long time, String format, Locale locale)时间戳转换成日期格式字符串static StringtimeStamp2Str(long time)时间戳转换成日期默认格式字符串static StringtoGMTString(Date date)
-
-
-
字段详细资料
-
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
- 另请参阅:
- 常量字段值
-
-
方法详细资料
-
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
-
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, String pattern)
- 参数:
date-pattern-- 返回:
- Date
-
isFirstDayInMonth
public static boolean isFirstDayInMonth(Date date)
判断传入的日期是不是当月的第一天- 参数:
date-- 返回:
- boolean
-
isFirstDayInYear
public static boolean isFirstDayInYear(Date date)
判断传入的日期是不是当年的第一天- 参数:
date-- 返回:
- boolean
-
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
-
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
-
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()
获取时区信息
-
-