public class DateUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
DATE_FORMAT_DATEONLY
要用到的DATE Format的定义.
|
static String |
DATE_FORMAT_DATETIME |
static String |
DATE_FORMAT_DATETIME14 |
static String |
HMS_FORMAT |
static org.slf4j.Logger |
LOGGER |
static String |
SHORTDATEFORMAT |
| 构造器和说明 |
|---|
DateUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static LocalDateTime |
addDay(LocalDateTime date,
int day)
计算 day 天后的时间.
|
static LocalDateTime |
addHour(LocalDateTime date,
int hour)
计算 hour 小时后的时间.
|
static LocalDateTime |
addMinute(LocalDateTime date,
int minute)
计算 minute 分钟后的时间.
|
static LocalDateTime |
addMoth(LocalDateTime date,
int month)
计算 month 月后的时间.
|
static LocalDateTime |
addSecond(LocalDateTime date,
int second)
计算 second 秒后的时间.
|
static LocalDateTime |
addYear(LocalDateTime date,
int year)
计算 year 年后的时间.
|
static String |
formaterDate(LocalDate date)
yyyy-MM-dd 格式化传入日期.
|
static String |
formaterDateToyyyyMMdd(LocalDate date)
yyyyMMdd 格式化传入日期.
|
static String |
formaterLocalDateTime(LocalDateTime dateTime)
将localDateTime 格式化成yyyy-MM-dd HH:mm:ss.
|
static String |
formaterLocalDateTime(LocalDateTime dateTime,
String dateFormat)
将localDateTime 格式化成特定格式的字符串.
|
static String |
formaterTime(LocalTime time,
String dateFormat)
将localDateTime 格式化成特定格式的字符串.
|
static LocalDateTime |
getAMonthFromNow()
获得当天近一月.
|
static LocalDateTime |
getAWeekFromNow()
获得当天近一周.
|
static LocalDateTime |
getAYearFromNow()
获得当天近一年.
|
static String |
getCurrentDate()
yyyy-MM-dd 当前日期.
|
static String |
getCurrentDateTime()
获取当前日期时间 yyyy-MM-dd HH:mm:ss.
|
static String |
getCurrentDateTime(String format)
获取当前日期时间.
|
static String |
getCurrentTime()
获取当前时间 hh:mm:ss.
|
static Date |
getDateYYYY()
Gets date yyyy.
|
static LocalDateTime |
getDayEnd(LocalDate date)
得到day的结束时间点。.
|
static long |
getDaysBetween(LocalDate t1,
LocalDate t2)
取得两个日期之间相差的日数.
|
static LocalDateTime |
getDayStart(LocalDate date)
得到day的起始时间点.
|
static long |
getHoursBetween(LocalDateTime t1,
LocalDateTime t2)
取得两个日期之间相差的小时数.
|
static long |
getMinutesBetween(LocalDateTime t1,
LocalDateTime t2)
取得两个日期之间相差的分钟.
|
static LocalDate |
getMonthEnd(LocalDate date)
得到month的终止时间点..
|
static long |
getMonthsBetween(LocalDate t1,
LocalDate t2)
取得两个日期之间相差的月数.
|
static LocalDate |
getMonthStart(LocalDate date)
得到当月起始时间.
|
static LocalDate |
getPreviousMonthFirstDay()
上月第一天.
|
static LocalDate |
getPreviousMonthLastDay()
上月最后一天.
|
static int |
getSeason(LocalDate date)
判断当前期为每几个季度.
|
static LocalDate[] |
getSeasonDate(LocalDate date)
取得季度月的第一天.
|
static LocalDate |
getSeasonEnd(LocalDate date)
取得季度最后一天.
|
static LocalDate |
getSeasonStart(LocalDate date)
取得季度第一天.
|
static long |
getSecondsBetween(LocalDateTime t1,
LocalDateTime t2)
取得两个日期之间相差的秒数.
|
static Date |
getTimesmorning()
获得当天0点时间.
|
static String |
getTimeStampStr(LocalDateTime date)
得到时间戳格式字串.
|
static LocalDateTime |
getUTCLocalDateTime()
获取utc时间.
|
static DayOfWeek |
getWeek()
获取今天是星期几.
|
static LocalDate |
getWeekEnd(LocalDate date)
得到当前周截止时间.
|
static LocalDate |
getWeekStart(LocalDate date)
得到传入日期,周起始时间.
|
static LocalDate |
getYearEnd(LocalDate date)
得到当前年最后一天.
|
static long |
getYearsBetween(LocalDate t1,
LocalDate t2)
取得两个日期之间相差的年数.
|
static LocalDate |
getYearStart(LocalDate date)
得到当前年起始时间.
|
static String |
getYesterday()
获取昨天的日期 格式串:yyyy-MM-dd.
|
static String |
getYesterday(LocalDate date)
获取昨天的日期 格式串:yyyy-MM-dd.
|
static boolean |
isBetween(LocalDateTime date,
LocalDateTime start,
LocalDateTime end)
判断时间是否在指定的时间段之类.
|
static boolean |
isBetween(LocalTime date,
LocalTime start,
LocalTime end)
判断时间是否在指定的时间段之类.
|
static boolean |
isOverIntervalLimit(LocalDate startDate,
LocalDate endDate,
int interval)
判断开始时间和结束时间,是否超出了当前时间的一定的间隔数限制 如:开始时间和结束时间,不能超出距离当前时间90天.
|
static boolean |
isSameDate(LocalDateTime date1,
LocalDateTime date2)
两个日期是否为同一天.
|
static long |
nowEpochSecond()
获取从1970年到现在的秒数.
|
static long |
nowTimeMillis()
获得当前的日期毫秒.
|
static Instant |
nowTimestamp()
获得当前的时间戳.
|
static Instant |
parseDataStrToInstant(String dateStr)
根据日期字符串获取时间戳.
|
static String |
parseDate(Date date)
Parse date string.
|
static String |
parseInstantToDataStr(Instant instant)
yyyy-MM-dd HH:mm:ss.
|
static LocalDate |
parseLocalDate(String str)
把字符串转成日期类型.
|
static LocalDate |
parseLocalDate(String str,
String format)
把字符串转成日期类型.
|
static LocalDateTime |
parseLocalDateTime(String str)
把字符串转成日期类型.
|
static LocalDateTime |
parseLocalDateTime(String str,
String dateFormat)
把字符串转成特定格式的日期类型.
|
static LocalDateTime |
parseLocalDateTime10(String str)
把字符串转成日期类型.
|
static String |
subDays(int days)
获取当前时间的前多少,yyyy-MM-dd.
|
static LocalDateTime |
toDefaultDateTime(LocalDateTime dateTime)
将UTC时间转成当前时区时间.
|
static LocalDateTime |
toDefaultDateTime(Timestamp timestamp)
To default date time local date time.
|
String |
toString() |
static LocalDateTime |
toUTCDateTime(LocalDateTime dateTime)
将当前时区时间转成UTC时间.
|
public static final org.slf4j.Logger LOGGER
public static final String DATE_FORMAT_DATEONLY
public static LocalDateTime parseLocalDateTime(String str) throws ParseException
str - 日期字符串ParseException - 异常LocalDateTimepublic static Date getDateYYYY() throws ParseException
ParseException - the parse exceptionpublic static String parseDate(Date date)
date - the datepublic static LocalDateTime parseLocalDateTime(String str, String dateFormat) throws ParseException
str - 日期字符串dateFormat - 日期字符串ParseException - 转换异常LocalDateTimepublic static LocalDateTime parseLocalDateTime10(String str) throws ParseException
str - 日期字符串ParseException - 异常LocalDateTimepublic static LocalDate parseLocalDate(String str) throws ParseException
str - 日期字符串ParseException - 异常LocalDateTimepublic static LocalDate parseLocalDate(String str, String format) throws ParseException
str - 日期字符串format - 日期格式ParseException - 异常LocalDateTimepublic static long nowTimeMillis()
public static long nowEpochSecond()
public static Instant nowTimestamp()
public static String getCurrentDate()
public static String getCurrentDateTime()
public static String getCurrentDateTime(String format)
format - 格式字符串public static String getCurrentTime()
public static String formaterDate(LocalDate date)
date - 日期public static String formaterTime(LocalTime time, String dateFormat)
time - 时间dateFormat - 格式化public static String formaterDateToyyyyMMdd(LocalDate date)
date - 传入的日期public static String formaterLocalDateTime(LocalDateTime dateTime)
dateTime - 时间public static String formaterLocalDateTime(LocalDateTime dateTime, String dateFormat)
dateTime - 时间dateFormat - 格式化public static String parseInstantToDataStr(Instant instant) throws ParseException
instant - 时间点.ParseException - 异常public static String getTimeStampStr(LocalDateTime date)
date - 长日期public static LocalDateTime addSecond(LocalDateTime date, int second)
date - 长日期second - 需要增加的秒数public static LocalDateTime addMinute(LocalDateTime date, int minute)
date - 长日期minute - 需要增加的分钟数public static LocalDateTime addHour(LocalDateTime date, int hour)
date - 长日期hour - 增加的小时数public static LocalDateTime addDay(LocalDateTime date, int day)
date - 长日期day - 增加的天数public static LocalDateTime addMoth(LocalDateTime date, int month)
date - 长日期month - 需要增加的月数public static LocalDateTime addYear(LocalDateTime date, int year)
date - 长日期year - 需要增加的年数public static LocalDateTime getDayStart(LocalDate date)
date - 短日期public static LocalDateTime getDayEnd(LocalDate date)
date - date 短日期public static Instant parseDataStrToInstant(String dateStr) throws ParseException
dateStr - yyyy-MM-dd HH:mm:ssParseException - 异常public static boolean isSameDate(LocalDateTime date1, LocalDateTime date2)
date1 - 时间date2 - 时间public static long getYearsBetween(LocalDate t1, LocalDate t2)
t1 - 开始时间t2 - 结果时间public static long getDaysBetween(LocalDate t1, LocalDate t2)
t1 - 开始日期t2 - 结束日期public static long getMonthsBetween(LocalDate t1, LocalDate t2)
t1 - 开始日期t2 - 结束日期public static long getHoursBetween(LocalDateTime t1, LocalDateTime t2)
t1 - 开始长日期t2 - 结束长日期public static long getSecondsBetween(LocalDateTime t1, LocalDateTime t2)
t1 - 开始长日期t2 - 结束长日期public static long getMinutesBetween(LocalDateTime t1, LocalDateTime t2)
t1 - 开始长日期t2 - 结束长日期public static boolean isBetween(LocalDateTime date, LocalDateTime start, LocalDateTime end)
date - 需要判断的时间start - 时间段的起始时间end - 时间段的截止时间public static boolean isBetween(LocalTime date, LocalTime start, LocalTime end)
date - 需要判断的时间start - 时间段的起始时间end - 时间段的截止时间public static LocalDate getWeekStart(LocalDate date)
date - 日期public static LocalDate getWeekEnd(LocalDate date)
date - 日期public static LocalDate getMonthEnd(LocalDate date)
date - 日期public static LocalDate getMonthStart(LocalDate date)
date - 日期public static LocalDate getYearStart(LocalDate date)
date - 日期public static LocalDate getYearEnd(LocalDate date)
date - 日期public static LocalDate getSeasonStart(LocalDate date)
date - 日期public static LocalDate getSeasonEnd(LocalDate date)
date - 日期public static LocalDate[] getSeasonDate(LocalDate date)
date - 日期public static int getSeason(LocalDate date)
date - 日期public static String subDays(int days)
days - 天数public static boolean isOverIntervalLimit(LocalDate startDate, LocalDate endDate, int interval)
startDate - 开始时间endDate - 结束时间按interval - 间隔数public static String getYesterday()
public static String getYesterday(LocalDate date)
date - 时间public static LocalDate getPreviousMonthFirstDay()
public static LocalDate getPreviousMonthLastDay()
public static Date getTimesmorning()
public static LocalDateTime getAWeekFromNow()
public static LocalDateTime getAMonthFromNow()
public static LocalDateTime getAYearFromNow()
public static LocalDateTime getUTCLocalDateTime()
public static LocalDateTime toUTCDateTime(LocalDateTime dateTime)
dateTime - 时间public static LocalDateTime toDefaultDateTime(LocalDateTime dateTime)
dateTime - 时间public static LocalDateTime toDefaultDateTime(Timestamp timestamp)
timestamp - the timestampCopyright © 2019 dromara. All rights reserved.