Package com.xxl.tool.core
Class DateTool
java.lang.Object
com.xxl.tool.core.DateTool
date util
- Author:
- xuxueli 2018-08-19 01:24:11
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSuch as "2020-12-28"static final StringSuch as "2020-12-28 10:00:00"static final longmillisecond per hourstatic final longmillisecond per minutestatic final longmillisecond per minutestatic final longmillisecond per month (30 days)static final longone millisecondstatic final longmillisecond per secondstatic final longmillisecond per weekstatic final longmillisecond per year (365 days)static final StringSuch as "10:00:00"static final StringSuch as "10:00" -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Dateadd Daysstatic Dateadd Hoursstatic DateaddMilliseconds(Date date, long amount) add Millisecondsstatic DateaddMinutes(Date date, long amount) add Minutesstatic Dateadd Monthsstatic DateaddSeconds(Date date, long amount) add Secondsstatic Dateadd Weeksstatic Dateadd Yearsstatic longbetweenDay(Date beginDate, Date endDate) between daystatic longbetweenHour(Date beginDate, Date endDate) between hourstatic longbetweenMinute(Date beginDate, Date endDate) between minutestatic longbetweenMonth(Date beginDate, Date endDate) between monthstatic longbetweenSecond(Date beginDate, Date endDate) between secondstatic longbetweenWeek(Date beginDate, Date endDate) between weekstatic longbetweenYear(Date beginDate, Date endDate) between yearstatic Stringformat Date to Stringstatic StringformatDate(Date date) format date;like "yyyy-MM-dd"static StringformatDateTime(Date date) format date;like "yyyy-MM-dd HH:mm:s"static StringformatTemporal(Temporal temporal, String pattern) format temporal to Stringstatic booleanis same daystatic Dateparse String to Date, with timestatic Dateparse String to Date, like "yyyy-MM-dd"static DateparseDateTime(String dateString) parse String to DateTime, like "yyyy-MM-dd HH:mm:s"static LocalDateparseLocalDate(String dateString, String pattern) parse String to LocalDatestatic LocalDateTimeparseLocalDateTime(String dateString, String pattern) parse String to LocalDateTimestatic LocalTimeparseLocalTime(String dateString, String pattern) parse String to LocalTimestatic YearMonthparseYearMonth(String dateString, String pattern) parse String to YearMonthstatic DateSet the specified field to a date, returning a new object.static Dateset day-of-month to a date, returning a new objectstatic Dateset hour-of-day to a date, returning a new objectstatic DatesetMilliseconds(Date date, int amount) set milliseconds to a date, returning a new objectstatic DatesetMinutes(Date date, int amount) set minutes to a date, returning a new objectstatic Dateset month to a date, returning a new objectstatic DatesetSeconds(Date date, int amount) set seconds to a date, returning a new objectstatic DatesetStartOfDay(Date date) set start of day to a date, like "yyyy-MM-dd 00:00:00"static Dateset year to a date, returning a new object
-
Field Details
-
DATE_TIME
Such as "2020-12-28 10:00:00"- See Also:
-
DATE
Such as "2020-12-28"- See Also:
-
TIME
Such as "10:00:00"- See Also:
-
TIME_WITHOUT_SECOND
Such as "10:00"- See Also:
-
MILLIS_PER_MS
public static final long MILLIS_PER_MSone millisecond- See Also:
-
MILLIS_PER_SECOND
public static final long MILLIS_PER_SECONDmillisecond per second- See Also:
-
MILLIS_PER_MINUTE
public static final long MILLIS_PER_MINUTEmillisecond per minute- See Also:
-
MILLIS_PER_HOUR
public static final long MILLIS_PER_HOURmillisecond per minute- See Also:
-
MILLIS_PER_DAY
public static final long MILLIS_PER_DAYmillisecond per hour- See Also:
-
MILLIS_PER_WEEK
public static final long MILLIS_PER_WEEKmillisecond per week- See Also:
-
MILLIS_PER_MONTH_30
public static final long MILLIS_PER_MONTH_30millisecond per month (30 days)- See Also:
-
MILLIS_PER_YEAR_365
public static final long MILLIS_PER_YEAR_365millisecond per year (365 days)- See Also:
-
-
Constructor Details
-
DateTool
public DateTool()
-
-
Method Details
-
parse
parse String to Date, with time- Parameters:
dateString-pattern-- Returns:
- date
-
parseDateTime
parse String to DateTime, like "yyyy-MM-dd HH:mm:s"- Parameters:
dateString-- Returns:
-
parseDate
parse String to Date, like "yyyy-MM-dd"- Parameters:
dateString-- Returns:
-
format
format Date to String- Parameters:
date- datepattern- pattern- Returns:
- date string
-
formatDate
format date;like "yyyy-MM-dd"- Parameters:
date-- Returns:
- Throws:
ParseException
-
formatDateTime
format date;like "yyyy-MM-dd HH:mm:s"- Parameters:
date-- Returns:
- Throws:
ParseException
-
parseLocalDateTime
parse String to LocalDateTime- Parameters:
dateString-pattern-- Returns:
-
parseLocalDate
parse String to LocalDate- Parameters:
dateString-pattern-- Returns:
-
parseLocalTime
parse String to LocalTime- Parameters:
dateString-pattern-- Returns:
-
parseYearMonth
parse String to YearMonth- Parameters:
dateString-pattern-- Returns:
-
formatTemporal
format temporal to String- Parameters:
temporal-pattern-- Returns:
-
addYears
add Years- Parameters:
date-amount-- Returns:
-
addMonths
add Months- Parameters:
date-amount-- Returns:
-
addDays
add Days- Parameters:
date-amount-- Returns:
-
addHours
add Hours- Parameters:
date-amount-- Returns:
-
addMinutes
add Minutes- Parameters:
date-amount-- Returns:
-
addSeconds
add Seconds- Parameters:
date-amount-- Returns:
-
addWeeks
add Weeks- Parameters:
date-amount-- Returns:
-
addMilliseconds
add Milliseconds- Parameters:
date-amount-- Returns:
-
set
Set the specified field to a date, returning a new object.- Parameters:
date- the original is unchanged,calendarField- like "Calendar.YEAR"amount- the amount to set- Returns:
-
setYears
set year to a date, returning a new object- Parameters:
date- the original is unchanged,amount- the amount to set- Returns:
-
setMonths
set month to a date, returning a new object- Parameters:
date- the first month of the year isJANUARY, which is 0;amount- the amount to set- Returns:
-
setDays
set day-of-month to a date, returning a new object- Parameters:
date- the original is unchanged,amount- the amount to set- Returns:
-
setHours
set hour-of-day to a date, returning a new object- Parameters:
date- the original is unchanged,amount- the amount to set- Returns:
-
setMinutes
set minutes to a date, returning a new object- Parameters:
date- the original is unchanged,amount- the amount to set- Returns:
-
setSeconds
set seconds to a date, returning a new object- Parameters:
date- the original is unchanged,amount- the amount to set- Returns:
-
setMilliseconds
set milliseconds to a date, returning a new object- Parameters:
date- the original is unchanged,amount- the amount to set- Returns:
-
setStartOfDay
set start of day to a date, like "yyyy-MM-dd 00:00:00"- Parameters:
date- the original is unchanged,- Returns:
- return the start of day, like "yyyy-MM-dd 00:00:00"
-
betweenYear
between year- Parameters:
beginDate-endDate-- Returns:
-
betweenMonth
between month- Parameters:
beginDate-endDate-- Returns:
-
betweenDay
between day- Parameters:
beginDate-endDate-- Returns:
-
betweenHour
between hour- Parameters:
beginDate-endDate-- Returns:
-
betweenMinute
between minute- Parameters:
beginDate-endDate-- Returns:
-
betweenSecond
between second- Parameters:
beginDate-endDate-- Returns:
-
betweenWeek
between week- Parameters:
beginDate-endDate-- Returns:
-
isSameDay
is same day- Parameters:
cal1-cal2-- Returns:
-