Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.apache.commons.lang.time.DateUtils
public class DateUtils
extends Object
Field Summary | |
static int |
|
static int |
|
static int |
|
static int |
|
static long |
|
static long |
|
static long |
|
static long |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static TimeZone |
|
Constructor Summary | |
|
Method Summary | |
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static Iterator |
|
static Iterator |
|
static Iterator |
|
static Date |
|
static Calendar |
|
static Date |
|
static Date |
|
static Calendar |
|
static Date |
|
static Date |
|
public static final int MILLIS_IN_DAY
Deprecated. Use MILLIS_PER_DAY. This will be removed in Commons Lang 3.0.
Number of milliseconds in a standard day.
- Field Value:
- 86400000
public static final int MILLIS_IN_HOUR
Deprecated. Use MILLIS_PER_HOUR. This will be removed in Commons Lang 3.0.
Number of milliseconds in a standard hour.
- Field Value:
- 3600000
public static final int MILLIS_IN_MINUTE
Deprecated. Use MILLIS_PER_MINUTE. This will be removed in Commons Lang 3.0.
Number of milliseconds in a standard minute.
- Field Value:
- 60000
public static final int MILLIS_IN_SECOND
Deprecated. Use MILLIS_PER_SECOND. This will be removed in Commons Lang 3.0.
Number of milliseconds in a standard second.
- Field Value:
- 1000
public static final long MILLIS_PER_DAY
Number of milliseconds in a standard day.
- Field Value:
- 86400000L
- Since:
- 2.1
public static final long MILLIS_PER_HOUR
Number of milliseconds in a standard hour.
- Field Value:
- 3600000L
- Since:
- 2.1
public static final long MILLIS_PER_MINUTE
Number of milliseconds in a standard minute.
- Field Value:
- 60000L
- Since:
- 2.1
public static final long MILLIS_PER_SECOND
Number of milliseconds in a standard second.
- Field Value:
- 1000L
- Since:
- 2.1
public static final int RANGE_MONTH_MONDAY
A month range, the week starting on Monday.
- Field Value:
- 6
public static final int RANGE_MONTH_SUNDAY
A month range, the week starting on Sunday.
- Field Value:
- 5
public static final int RANGE_WEEK_CENTER
A week range, centered around the day focused.
- Field Value:
- 4
public static final int RANGE_WEEK_MONDAY
A week range, starting on Monday.
- Field Value:
- 2
public static final int RANGE_WEEK_RELATIVE
A week range, starting on the day focused.
- Field Value:
- 3
public static final int RANGE_WEEK_SUNDAY
A week range, starting on Sunday.
- Field Value:
- 1
public static final int SEMI_MONTH
This is half a month, so this represents whether a date is in the top or bottom half of the month.
- Field Value:
- 1001
public static final TimeZone UTC_TIME_ZONE
The UTC time zone (often referred to as GMT).
public DateUtils()
DateUtils
instances should NOT be constructed in standard programming. Instead, the class should be used asDateUtils.parse(str);
. This constructor is public to permit tools that require a JavaBean instance to operate.
public static boolean isSameDay(Calendar cal1, Calendar cal2)
Checks if two calendar objects are on the same day ignoring time. 28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true. 28 Mar 2002 13:45 and 12 Mar 2002 13:45 would return false.
- Parameters:
cal1
- the first calendar, not altered, not nullcal2
- the second calendar, not altered, not null
- Returns:
- true if they represent the same day
- Since:
- 2.1
public static boolean isSameDay(Date date1, Date date2)
Checks if two date objects are on the same day ignoring time. 28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true. 28 Mar 2002 13:45 and 12 Mar 2002 13:45 would return false.
- Parameters:
date1
- the first date, not altered, not nulldate2
- the second date, not altered, not null
- Returns:
- true if they represent the same day
- Since:
- 2.1
public static boolean isSameInstant(Calendar cal1, Calendar cal2)
Checks if two calendar objects represent the same instant in time. This method compares the long millisecond time of the two objects.
- Parameters:
cal1
- the first calendar, not altered, not nullcal2
- the second calendar, not altered, not null
- Returns:
- true if they represent the same millisecond instant
- Since:
- 2.1
public static boolean isSameInstant(Date date1, Date date2)
Checks if two date objects represent the same instant in time. This method compares the long millisecond time of the two objects.
- Parameters:
date1
- the first date, not altered, not nulldate2
- the second date, not altered, not null
- Returns:
- true if they represent the same millisecond instant
- Since:
- 2.1
public static boolean isSameLocalTime(Calendar cal1, Calendar cal2)
Checks if two calendar objects represent the same local time. This method compares the values of the fields of the two objects. In addition, both calendars must be the same of the same type.
- Parameters:
cal1
- the first calendar, not altered, not nullcal2
- the second calendar, not altered, not null
- Returns:
- true if they represent the same millisecond instant
- Since:
- 2.1
public static Iterator iterator(Calendar focus, int rangeStyle)
This constructs anIterator
that will start and stop over a date range based on the focused date and the range style. For instance, passing Thursday, July 4, 2002 and aRANGE_MONTH_SUNDAY
will return anIterator
that starts with Sunday, June 30, 2002 and ends with Saturday, August 3, 2002.
- Parameters:
focus
- the date to work withrangeStyle
- the style constant to use. Must be one ofRANGE_MONTH_SUNDAY
,RANGE_MONTH_MONDAY
,RANGE_WEEK_SUNDAY
,RANGE_WEEK_MONDAY
,RANGE_WEEK_RELATIVE
,RANGE_WEEK_CENTER
- Returns:
- the date iterator
public static Iterator iterator(Date focus, int rangeStyle)
This constructs anIterator
that will start and stop over a date range based on the focused date and the range style. For instance, passing Thursday, July 4, 2002 and aRANGE_MONTH_SUNDAY
will return anIterator
that starts with Sunday, June 30, 2002 and ends with Saturday, August 3, 2002.
- Parameters:
focus
- the date to work withrangeStyle
- the style constant to use. Must be one of the range styles listed for theiterator(Calendar,int)
method.
- Returns:
- the date iterator
public static Iterator iterator(Object focus, int rangeStyle)
This constructs anIterator
that will start and stop over a date range based on the focused date and the range style. For instance, passing Thursday, July 4, 2002 and aRANGE_MONTH_SUNDAY
will return anIterator
that starts with Sunday, June 30, 2002 and ends with Saturday, August 3, 2002.
- Parameters:
focus
- the date to work with, eitherDate
orCalendar
rangeStyle
- the style constant to use. Must be one of the range styles listed for theiterator(Calendar,int)
method.
- Returns:
- the date iterator
public static Date parseDate(String str, String[] parsePatterns) throws ParseException
Parses a string representing a date by trying a variety of different parsers. The parse will try each parse pattern in turn. A parse is only deemed sucessful if it parses the whole of the input string. If no parse patterns match, a ParseException is thrown.
- Parameters:
str
- the date to parse, not nullparsePatterns
- the date format patterns to use, see SimpleDateFormat, not null
- Returns:
- the parsed date
public static Calendar round(Calendar date, int field)
Round this date, leaving the field specified as the most significant field. For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if this was passed with HOUR, it would return 28 Mar 2002 14:00:00.000. If this was passed with MONTH, it would return 1 April 2002 0:00:00.000. For a date in a timezone that handles the change to daylight saving time, rounding to Calendar.HOUR_OF_DAY will behave as follows. Suppose daylight saving time begins at 02:00 on March 30. Rounding a date that crosses this time would produce the following values:
- March 30, 2003 01:10 rounds to March 30, 2003 01:00
- March 30, 2003 01:40 rounds to March 30, 2003 03:00
- March 30, 2003 02:10 rounds to March 30, 2003 03:00
- March 30, 2003 02:40 rounds to March 30, 2003 04:00
- Parameters:
date
- the date to work withfield
- the field fromCalendar
orSEMI_MONTH
- Returns:
- the rounded date (a different object)
public static Date round(Date date, int field)
Round this date, leaving the field specified as the most significant field. For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if this was passed with HOUR, it would return 28 Mar 2002 14:00:00.000. If this was passed with MONTH, it would return 1 April 2002 0:00:00.000. For a date in a timezone that handles the change to daylight saving time, rounding to Calendar.HOUR_OF_DAY will behave as follows. Suppose daylight saving time begins at 02:00 on March 30. Rounding a date that crosses this time would produce the following values:
- March 30, 2003 01:10 rounds to March 30, 2003 01:00
- March 30, 2003 01:40 rounds to March 30, 2003 03:00
- March 30, 2003 02:10 rounds to March 30, 2003 03:00
- March 30, 2003 02:40 rounds to March 30, 2003 04:00
- Parameters:
date
- the date to work withfield
- the field fromCalendar
orSEMI_MONTH
- Returns:
- the rounded date
public static Date round(Object date, int field)
Round this date, leaving the field specified as the most significant field. For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if this was passed with HOUR, it would return 28 Mar 2002 14:00:00.000. If this was passed with MONTH, it would return 1 April 2002 0:00:00.000. For a date in a timezone that handles the change to daylight saving time, rounding to Calendar.HOUR_OF_DAY will behave as follows. Suppose daylight saving time begins at 02:00 on March 30. Rounding a date that crosses this time would produce the following values:
- March 30, 2003 01:10 rounds to March 30, 2003 01:00
- March 30, 2003 01:40 rounds to March 30, 2003 03:00
- March 30, 2003 02:10 rounds to March 30, 2003 03:00
- March 30, 2003 02:40 rounds to March 30, 2003 04:00
- Parameters:
date
- the date to work with, either Date or Calendarfield
- the field fromCalendar
orSEMI_MONTH
- Returns:
- the rounded date
public static Calendar truncate(Calendar date, int field)
Truncate this date, leaving the field specified as the most significant field. For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000. If this was passed with MONTH, it would return 1 Mar 2002 0:00:00.000.
- Parameters:
date
- the date to work withfield
- the field fromCalendar
orSEMI_MONTH
- Returns:
- the rounded date (a different object)
public static Date truncate(Date date, int field)
Truncate this date, leaving the field specified as the most significant field. For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000. If this was passed with MONTH, it would return 1 Mar 2002 0:00:00.000.
- Parameters:
date
- the date to work withfield
- the field fromCalendar
orSEMI_MONTH
- Returns:
- the rounded date
public static Date truncate(Object date, int field)
Truncate this date, leaving the field specified as the most significant field. For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000. If this was passed with MONTH, it would return 1 Mar 2002 0:00:00.000.
- Parameters:
date
- the date to work with, eitherDate
orCalendar
field
- the field fromCalendar
orSEMI_MONTH
- Returns:
- the rounded date