public class DateUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
DATE_PATTERN |
static long |
DATE_TIME |
static long |
DATE_TIME_SECOND |
static String |
DEFAULT_PATTERN |
static String |
DEFAULT_TIMESTAMP_PATTERN |
static String |
EMPTY_SRING |
static long |
HOUR_TIME |
static long |
MINUTE_TIME |
static long |
SECOND_TIME |
static long |
TEN_MINUTE_TIME |
static long |
TIME_ZONE |
static String |
TIME_ZONE_STRING |
| 构造器和说明 |
|---|
DateUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
analyzeTime(long time,
boolean showFull)
把时间戳转为指定显示格式
|
static boolean |
checkAfterTime(Date date,
String time)
检查传入的时间是否在当前时间小时数之后
|
static String |
convertDate(Date date)
把日期转换成yyyy-MM-dd HH:mm:ss格式
|
static String |
convertDate(Date date,
String pattern)
把日期转换成pattern格式
|
static String |
convertLebal(Date startTime,
Date endTime,
boolean showSuffix)
时间标签 返回两个时间的间隔
|
static String |
convertLebalFull(Date startTime,
Date endTime,
boolean showSuffix)
时间标签 返回两个时间的间隔
|
static Date |
convertStringToDate(String date) |
static Date |
convertStringToDate(String date,
String pattern) |
static Date |
dateAdd(Date date,
int day)
把时间加上day天后返回,如果传负数代表减day天
|
static Date |
dateAddDays(Date startDate,
int days)
时间加减天数
|
static Date |
dateAddHours(Date startDate,
int hours)
时间加减小时
|
static Date |
dateAddMinutes(Date startDate,
int minutes)
时间加减分钟
|
static Date |
dateAddMonth(Date date,
int month)
多少个月前后的今天
|
static Date |
dateAddMonths(Date startDate,
int months)
时间加减月数
|
static Date |
dateAddSeconds(Date startDate,
int seconds)
时间加减秒数
|
static Date |
dateAddYears(Date startDate,
int years)
时间加减年数
|
static int |
dateCompare(Date myDate,
Date compareDate)
时间比较(如果myDate>compareDate返回1,<返回-1,相等返回0)
|
static Date |
dateMax(Date date,
Date compareDate)
获取两个时间中最大的一个时间
|
static Date |
dateMin(Date date,
Date compareDate)
获取两个时间中最小的一个时间
|
static int |
getBetweenDateDays(Date startTime,
Date endTime)
获取两个日期之间的间隔天数
|
static int |
getDate(Date date)
获取日期时间的第几天(即返回日期的dd),如2017-02-13,返回13
|
static List<String> |
getDateRange(String beginDate,
String endDate,
int type)
获取两个时间段之间相差日期列表
|
static Date |
getFirstDayOfMonth()
获取本月的第一天
|
static Date |
getFirstDayOfMonth(Date date)
获取本月的第一天
|
static Date |
getFirstDayOfPreviousMonth()
获取上一个月的第一天
|
static Date |
getFirstDayOfPreviousYear()
获取上一年的第一天
|
static int |
getMonth(Date date)
获取日期时间的月份,如2017年2月13日,返回2
|
static String |
getOffsetStringDate(long offsetTime)
将一个时间戳,根据其大小转换为对应的‘时分秒毫秒’不同组合的字符串
|
static long |
getTimeZone()
获取时区信息
|
static String |
getTimeZoneString()
获取时区信息
|
static Date |
getToday()
获取当前时间的日期
|
static Date |
getTomorrow()
获取明天的日期
|
static String |
getWeekDay(Calendar c)
获取星期几
|
static int |
getYear(Date date)
获取日期时间的年份,如2017-02-13,返回2017
|
static Date |
getYesterday()
获取昨天的日期
|
static boolean |
isEmpty(Object obj)
判断对象是否为空
|
static boolean |
isFirstDayInMonth(Date date)
判断传入的日期是不是当月的第一天
|
static boolean |
isFirstDayInYear(Date date)
判断传入的日期是不是当年的第一天
|
static boolean |
isSameDay(long time1,
long time2)
时间戳转换成日期格式字符串
|
static boolean |
isSameDayBySecond(long time1,
long time2)
比较两个时间是否为同一天
|
static long |
millisToMinutes(long millis)
Converts millis to minutes
|
static long |
millisToSeconds(long millis)
Converts millis to seconds
|
static long |
minutesToMillis(long minutes)
Converts minutes to millis
|
static Date |
rounding(Date date)
去掉时分秒后返回
|
static long |
secondsToMillis(long seconds)
Converts seconds to millis
|
static long |
timeAfterMillis(long millis)
Returns timestamp in the future after some millis passed from now
|
static String |
timeStamp2DateStr(long time)
时间戳转换成日期默认格式字符串
|
static String |
timeStamp2DateStr(long time,
String format)
时间戳转换成日期格式字符串
|
static String |
timeStamp2DateStr(long time,
String format,
Locale locale)
时间戳转换成日期格式字符串
|
static String |
timeStamp2Str(long time)
时间戳转换成日期默认格式字符串
|
static String |
toGMTString(Date date) |
public static final long DATE_TIME
public static final long DATE_TIME_SECOND
public static final long HOUR_TIME
public static final long MINUTE_TIME
public static final long SECOND_TIME
public static final long TIME_ZONE
public static final String TIME_ZONE_STRING
public static final long TEN_MINUTE_TIME
public static long minutesToMillis(long minutes)
minutes - time in minutespublic static long secondsToMillis(long seconds)
seconds - time in secondspublic static long millisToMinutes(long millis)
millis - time in millispublic static long millisToSeconds(long millis)
millis - time in millispublic static long timeAfterMillis(long millis)
millis - millis countpublic static String convertDate(Date date)
date - public static String convertDate(Date date, String pattern)
date - pattern - public static Date convertStringToDate(String date, String pattern)
date - pattern - public static boolean isFirstDayInMonth(Date date)
date - public static boolean isFirstDayInYear(Date date)
date - public static Date dateAdd(Date date, int day)
date - day - public static Date dateAddMonth(Date date, int month)
date - month - public static Date getFirstDayOfPreviousMonth()
public static Date getFirstDayOfMonth()
public static Date getFirstDayOfPreviousYear()
public static List<String> getDateRange(String beginDate, String endDate, int type)
beginDate - 开始时间endDate - 结束时间type - 1表示获取两个时间之间相差的“月份-日期”列表,2表示两个时间之间相差的“年份-月份”列表public static boolean isEmpty(Object obj)
obj - 对象public static String convertLebalFull(Date startTime, Date endTime, boolean showSuffix)
startTime - 开始时间endTime - 结束时间showSuffix - 是否添加“前”/“后”标签public static String convertLebal(Date startTime, Date endTime, boolean showSuffix)
startTime - 开始时间endTime - 结束时间showSuffix - 是否添加“前”/“后”标签public static String analyzeTime(long time, boolean showFull)
time - 时间showFull - 是否全显示public static Date getToday()
public static Date getYesterday()
public static int getBetweenDateDays(Date startTime, Date endTime)
startTime - endTime - public static Date getTomorrow()
public static boolean checkAfterTime(Date date, String time)
date - time - public static String getOffsetStringDate(long offsetTime)
offsetTime - 时间public static Date dateAddHours(Date startDate, int hours)
startDate - 要处理的时间,Null则为当前时间hours - 加减的小时public static Date dateAddMinutes(Date startDate, int minutes)
startDate - 要处理的时间,Null则为当前时间minutes - 加减的分钟public static Date dateAddSeconds(Date startDate, int seconds)
startDate - 要处理的时间,Null则为当前时间seconds - 加减的秒数public static Date dateAddDays(Date startDate, int days)
startDate - 要处理的时间,Null则为当前时间days - 加减的天数public static Date dateAddMonths(Date startDate, int months)
startDate - 要处理的时间,Null则为当前时间months - 加减的月数public static Date dateAddYears(Date startDate, int years)
startDate - 要处理的时间,Null则为当前时间years - 加减的年数public static int dateCompare(Date myDate, Date compareDate)
myDate - 时间compareDate - 要比较的时间public static Date dateMin(Date date, Date compareDate)
date - 被比较时间compareDate - 比较时间public static Date dateMax(Date date, Date compareDate)
date - 被比较时间compareDate - 比较时间public static int getYear(Date date)
date - public static int getMonth(Date date)
date - public static int getDate(Date date)
date - public static String timeStamp2DateStr(long time)
time - 时间戳public static String timeStamp2Str(long time)
time - 时间戳public static String timeStamp2DateStr(long time, String format)
time - 时间戳format - 日期字符串格式public static String timeStamp2DateStr(long time, String format, Locale locale)
time - 时间戳format - 日期字符串格式public static boolean isSameDay(long time1,
long time2)
time1 - 时间戳1(毫秒)time2 - 时间戳2(毫秒)public static boolean isSameDayBySecond(long time1,
long time2)
time1 - 时间戳1(秒)time2 - 时间戳2(秒)public static long getTimeZone()
public static String getTimeZoneString()
Copyright © 2021. All rights reserved.