Class DateUtil
java.lang.Object
com.codename1.util.DateUtil
Utility class for working with dates and timezones.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intCompares two dates.static Comparator<Date> compareByDateField(long field) Compares two dates or sorts multiple dates by the granularity of a specific field.intgetOffset(long date) Gets the offset from GMT in milliseconds for the given date.getTimeAgo(Date date) Gets the date in "time ago" format.booleaninDaylightTime(Date date) Checks whether the given date is in daylight savings time for the given date.booleanChecks if two times are on the same day usingCalendar.booleanChecks if two dates are on the same day in the current timezone.booleanisSameHour(Calendar c1, Calendar c2) Checks if two times are on the same hour usingCalendar.booleanisSameHour(Date d1, Date d2) Checks if two dates are on the same hour in the current timezone.booleanisSameMinute(Calendar c1, Calendar c2) Checks if two times are on the same minute usingCalendar.booleanisSameMinute(Date d1, Date d2) Checks if two dates are on the same minute in the current timezone.booleanisSameMonth(Calendar c1, Calendar c2) Checks if two times are on the same month usingCalendar.booleanisSameMonth(Date d1, Date d2) Checks if two dates are on the same month in the current timezone.booleanisSameSecond(Calendar c1, Calendar c2) Checks if two times are on the same second usingCalendar.booleanisSameSecond(Date d1, Date d2) Checks if two dates are on the same second in the current timezone.booleanisSameTime(Calendar c1, Calendar c2) Checks if two times are on the same time usingCalendar.booleanisSameTime(Date d1, Date d2) Checks if two dates are on the same time in the current timezone.booleanisSameYear(Calendar c1, Calendar c2) Checks if two times are on the same year usingCalendar.booleanisSameYear(Date d1, Date d2) Checks if two dates are on the same year in the current timezone.static DateReturns the latest of a set of dates.static DateReturns the earliest of a set of dates.
-
Field Details
-
MILLISECOND
public static final long MILLISECOND- See Also:
-
SECOND
public static final long SECOND- See Also:
-
MINUTE
public static final long MINUTE- See Also:
-
HOUR
public static final long HOUR- See Also:
-
DAY
public static final long DAY- See Also:
-
MONTH
public static final long MONTH- See Also:
-
YEAR
public static final long YEAR- See Also:
-
-
Constructor Details
-
DateUtil
Constructor for timezone.
Parameters
tz: Timezone
-
DateUtil
public DateUtil()Creates DateUtil object in default timezone.
-
-
Method Details
-
min
-
compare
-
compareByDateField
Compares two dates or sorts multiple dates by the granularity of a specific field.
Compare dates:
compareByDateField(DateUtil.MONTH).compare(date1, date2)Sort dates:
dateList.sort(compareByDateField(DateUtil.MONTH))Parameters
-
field: @param field One of the fields: -
DateUtil.MILLISECOND -
DateUtil.SECOND -
DateUtil.MINUTE -
DateUtil.HOUR -
DateUtil.DATE -
DateUtil.MONTH -
DateUtil.YEAR
Returns
- Returns:
-
0 - if first date is earlier.
-
< 0 - if first date is later.
-
== 0 - if they are equal.
Since
7.0
-
-
-
max
-
getOffset
public int getOffset(long date) Gets the offset from GMT in milliseconds for the given date.
Parameters
date: The date at which the offset is calculated.
Returns
Millisecond offset from GMT in the current timezone for the given date.
-
inDaylightTime
Checks whether the given date is in daylight savings time for the given date.
Parameters
date: the date to check
Returns
True if date is in daylight savings time
-
isSameYear
-
isSameYear
-
isSameMonth
-
isSameMonth
-
isSameDay
-
isSameDay
-
isSameHour
-
isSameHour
-
isSameMinute
-
isSameMinute
-
isSameSecond
-
isSameSecond
-
isSameTime
-
isSameTime
-
getTimeAgo
-