public final class DateUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.util.TimeZone |
GMT_ZONE
the GMT ZONE.
|
static java.lang.String |
RFC1123_PATTERN
RFC1123 PATTERN.
|
static java.lang.String |
TYPE_LAST_YEAR
User date Last year
|
static java.lang.String |
TYPE_NOW
User date NOW
|
static java.lang.String |
TYPE_TODAY
User date TODAY
|
static java.lang.String |
TYPE_TOMORROW
User date TOMORROW
|
static java.lang.String |
TYPE_YESTERDAY
User date YESTERDAY
|
Modifier and Type | Method and Description |
---|---|
static java.util.Date |
dateAdd(java.util.Date start,
java.lang.String type,
int value) |
static long |
dateDiff(java.util.Date start,
java.util.Date end,
java.lang.String type)
get the date difference with the default time zone.
|
static long |
dateDiff(java.util.Date start,
java.util.Date end,
java.lang.String type,
java.util.TimeZone tzStart,
java.util.TimeZone tzEnd)
get the date difference with the given time zones and dates
|
static int |
getCurrentYear(java.util.TimeZone timeZone)
This function returns the current year
|
static int |
getDayOfMonth(java.util.TimeZone timeZone,
java.util.Date date,
int givenDay,
int occurence)
This function returns the first given day of the month of the date passed
|
static java.lang.String |
getDayOfWeek(java.util.TimeZone timeZone,
java.util.Date date,
boolean inLongFormat)
getDayOfWeek returns the day of week
|
static int |
getDayOfWeekInt(java.util.TimeZone timeZone,
java.util.Date date)
getDayOfWeek returns the day of week in integer
|
static int |
getFirstWeekDayOfMonth(java.util.TimeZone timeZone,
java.util.Date date)
This function returns the first business/week day of the month of the date passed
|
static int |
getLastWeekDayOfMonth(java.util.TimeZone timeZone,
java.util.Date date)
This function returns the last business/weekday day of the month of the date passed
|
static java.lang.String |
getStdFormat(java.util.Date date,
java.util.TimeZone timeZone) |
static java.util.Date |
getToday(java.util.TimeZone timeZone)
Gets current date with no time
|
static java.util.GregorianCalendar |
getTodayGC(java.util.TimeZone timeZone)
Gets current date with no time
|
static java.util.Date |
getTommorrow(java.util.TimeZone timeZone)
This function returns the date for tomorrow
|
static int |
getWeekDayOfMonth(java.util.TimeZone timeZone,
java.util.Date date,
int occurence)
This function returns the WeekDay/business day of the month like., first, second, third ..etc based on occurrence.
|
static long |
getWeekDaysBetween(java.util.TimeZone timeZone,
java.util.Date start,
java.util.Date end)
This function returns the WeekDays between start date and end date,
|
static int |
getWeekendDayOfMonth(java.util.TimeZone timeZone,
java.util.Date date,
int occurence)
This function returns the Weekend day of the month like., first, second, third ..etc based on occurrence.
|
static java.util.Date |
getYesterday(java.util.TimeZone timeZone)
This function returns the date for yesterday
|
static boolean |
isWeekDay(int day)
This function checks if the day passed is a week day
|
static java.util.GregorianCalendar |
makeGC(java.util.TimeZone timeZone,
java.util.Date date)
initializes a calendar with the passed in timezone ( GMT if null) and the date ( current time if null)
|
static int |
monthsBetween(java.util.Date start,
java.util.Date end)
Different in months
|
static java.util.Date |
parse(java.lang.String format,
java.lang.String value) |
static java.util.Date |
parseUserDate(java.lang.String userDate,
java.util.TimeZone timeZone,
boolean allowFutureDates) |
static java.lang.String |
toJSON(java.util.Date date) |
static java.util.Date |
weekEnd(java.util.Date dt,
java.util.TimeZone timeZone) |
public static final java.lang.String TYPE_NOW
public static final java.lang.String TYPE_TODAY
public static final java.lang.String TYPE_TOMORROW
public static final java.lang.String TYPE_YESTERDAY
public static final java.lang.String TYPE_LAST_YEAR
public static final java.util.TimeZone GMT_ZONE
public static final java.lang.String RFC1123_PATTERN
@CheckReturnValue public static long dateDiff(java.util.Date start, java.util.Date end, java.lang.String type)
dateDiff( Date start, Date end, String type, TimeZone tzStart, TimeZone tzEnd)
method as possible as you could.start
- start dateend
- end datetype
- return value type@CheckReturnValue public static long dateDiff(java.util.Date start, java.util.Date end, java.lang.String type, java.util.TimeZone tzStart, java.util.TimeZone tzEnd)
start
- start dateend
- end datetype
- return value typetzStart
- time zone of the start datetzEnd
- time zone of the end date@CheckReturnValue @Nonnull public static java.lang.String toJSON(@Nonnull java.util.Date date)
@CheckReturnValue @Nonnull public static java.util.Date dateAdd(java.util.Date start, java.lang.String type, int value)
start
- start datetype
- type of valuevalue
- value to be added@CheckReturnValue @Nonnull public static java.util.Date weekEnd(@Nonnull java.util.Date dt, @Nullable java.util.TimeZone timeZone)
dt
- timeZone
- the timezone.@CheckReturnValue public static boolean isWeekDay(int day)
day
- WeekDay@CheckReturnValue public static int getFirstWeekDayOfMonth(java.util.TimeZone timeZone, java.util.Date date)
timeZone
- the user's timezonedate
- the date to check@CheckReturnValue public static int getDayOfMonth(java.util.TimeZone timeZone, java.util.Date date, int givenDay, int occurence) throws java.lang.Exception
timeZone
- the user's time zonedate
- the date to checkoccurence
- Example, 2 represents the 2nd occurrence of the day from 1 to 31.givenDay
- the day to find out in the monthjava.lang.Exception
- A serious problem occurred@CheckReturnValue public static int getWeekendDayOfMonth(java.util.TimeZone timeZone, java.util.Date date, int occurence)
timeZone
- the user's time zonedate
- the date to checkoccurence
- can have values like -4,-3, -2, -1, 1, 2, 3,4@CheckReturnValue @Nonnull public static int getWeekDayOfMonth(java.util.TimeZone timeZone, java.util.Date date, int occurence) throws java.lang.Exception
timeZone
- the user's time zonedate
- the date to checkoccurence
- can have values like -20... -3, -2, -1, 1, 2, 3 ...20java.lang.Exception
- A serious problem occurs@CheckReturnValue public static long getWeekDaysBetween(java.util.TimeZone timeZone, java.util.Date start, java.util.Date end) throws java.lang.Exception
timeZone
- the user's time zonestart
- start dateend
- end datejava.lang.Exception
- A serious problem occurs@CheckReturnValue public static int getLastWeekDayOfMonth(java.util.TimeZone timeZone, java.util.Date date)
timeZone
- the user's timezonedate
- the date to check@CheckReturnValue public static int getDayOfWeekInt(java.util.TimeZone timeZone, java.util.Date date)
timeZone
- The time zonedate
- The date to be checked@CheckReturnValue @Nonnull public static java.lang.String getDayOfWeek(java.util.TimeZone timeZone, java.util.Date date, boolean inLongFormat)
timeZone
- The time zonedate
- The date to be checkedinLongFormat
- The format of the weekday format i.e. [true: Sunday] | [false: Sun]@CheckReturnValue @Nonnull public static java.util.GregorianCalendar makeGC(@Nullable java.util.TimeZone timeZone, @Nullable java.util.Date date)
timeZone
- the user's timezonedate
- the date to set the calendar to.@CheckReturnValue @Nonnull public static java.util.GregorianCalendar getTodayGC(java.util.TimeZone timeZone)
timeZone
- the user's timezone@CheckReturnValue @Nonnull public static java.util.Date getToday(java.util.TimeZone timeZone)
timeZone
- the user's timezone@CheckReturnValue @Nonnull public static java.util.Date getTommorrow(java.util.TimeZone timeZone)
timeZone
- the user's timezone@CheckReturnValue @Nonnull public static java.util.Date getYesterday(java.util.TimeZone timeZone)
timeZone
- the user's timezone@CheckReturnValue public static int getCurrentYear(java.util.TimeZone timeZone)
timeZone
- the user's timezone@CheckReturnValue @Nonnull public static java.util.Date parseUserDate(java.lang.String userDate, java.util.TimeZone timeZone, boolean allowFutureDates) throws InvalidDataException
userDate
- timeZone
- the user's timezoneallowFutureDates
- InvalidDataException
@CheckReturnValue @Nonnull public static java.lang.String getStdFormat(@Nonnull java.util.Date date, @Nullable java.util.TimeZone timeZone)
date
- timeZone
- the user's timezone@CheckReturnValue @Nonnull public static java.util.Date parse(@Nonnull java.lang.String format, @Nonnull java.lang.String value) throws java.lang.Exception
format
- value
- the valuejava.lang.Exception
- a serious problem@CheckReturnValue public static int monthsBetween(@Nonnull java.util.Date start, @Nonnull java.util.Date end)
start
- start dateend
- end datestSoftware Copyright © 2001-2014 stSoftware All Rights Reserved.