com.foxsmart.ic.util
Class DateUtils

java.lang.Object
  extended by org.apache.commons.lang.time.DateUtils
      extended by com.foxsmart.ic.util.DateUtils

public class DateUtils
extends org.apache.commons.lang.time.DateUtils

This class provides various date and time utilities via static methods.


Field Summary
static java.lang.String DATE_FORMAT_DD_MMM_YYYY
          The date format of "dd MMM yyyy"
static java.lang.String DATE_FORMAT_MMM_D_YYYY
          The date format of "MMMM d, yyyy"
static java.lang.String DEFAULT_DATE_FORMAT
          The default date format of "MMMM d, yyyy"
static java.lang.String DEFAULT_TIME_FORMAT
          The default time format of "MMM d, yyyy h:mm:ss a"
static java.lang.String TIME_FORMAT_MMM_D_YYYY_H_MM_A
          The time format of "MMM d, yyyy h:mm a"
 
Fields inherited from class org.apache.commons.lang.time.DateUtils
MILLIS_IN_DAY, MILLIS_IN_HOUR, MILLIS_IN_MINUTE, MILLIS_IN_SECOND, MILLIS_PER_DAY, MILLIS_PER_HOUR, MILLIS_PER_MINUTE, MILLIS_PER_SECOND, RANGE_MONTH_MONDAY, RANGE_MONTH_SUNDAY, RANGE_WEEK_CENTER, RANGE_WEEK_MONDAY, RANGE_WEEK_RELATIVE, RANGE_WEEK_SUNDAY, SEMI_MONTH, UTC_TIME_ZONE
 
Constructor Summary
DateUtils()
           
 
Method Summary
static java.lang.String formatCalendar(java.util.Calendar calendar)
          Formats the passed in calendar into a dd-MMM-yyyy HH:mm:ss format.
static java.lang.String formatCalendar(java.util.Calendar calendar, java.lang.String format)
          Formats the passed in calendar into the format specified.
static java.lang.String formatDate(java.util.Date date)
          Formats the passed in date with the default format and returns it as a String.
static java.lang.String formatDate(java.util.Date date, java.lang.String format)
          Formats the passed in date and returns it as a String.
static java.lang.String formatElapsedTime(long elapsedTime, boolean displayMilliseconds)
          Formats an elapsed period of time in milliseconds.
static java.lang.String formatTime(java.util.Calendar calendar)
          Formats the passed in date/time and returns it as a String.
static java.lang.String formatTime(java.util.Date date)
          Formats the passed in date/time with the default format and returns it as a String.
static java.lang.String formatTime(java.util.Date date, java.lang.String format)
          Formats the passed in date/time and returns it as a String.
static java.util.Calendar getCalendarUsingFormat(java.lang.String dateString, java.lang.String dateFormat)
          Gets a Calendar from the passed in date as a String.
static java.util.Calendar getCalendarUsingFormats(java.lang.String dateString, java.lang.String[] dateFormats)
          Gets a Calendar from the passed in date as a String.
static java.util.Calendar getCurrentDayAtMidnight()
          Gets the current date at midnight.
static long getElapsedDays(java.util.Calendar startTime, java.util.Calendar endTime)
          Gets the elapsed number of days between the start and end times.
static long getElapsedDays(long elapsedTime)
          Gets the elapsed number of days given the elapsed miliseconds.
static long getElapsedTime(java.lang.String key)
          Get elapsed time from a previously started timer.
static java.lang.String getMonth(int month)
          Gets the string month based on the passed in integer month.
static int getMonth(java.lang.String month)
          Get the integer month based on the spelled out month.
static java.lang.String startTimer()
          Starts a timer and returns a key to this timer.
static long stopTimer(java.lang.String key)
          Stops a previously started timer.
 
Methods inherited from class org.apache.commons.lang.time.DateUtils
add, addDays, addHours, addMilliseconds, addMinutes, addMonths, addSeconds, addWeeks, addYears, isSameDay, isSameDay, isSameInstant, isSameInstant, isSameLocalTime, iterator, iterator, iterator, parseDate, round, round, round, truncate, truncate, truncate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DATE_FORMAT

public static final java.lang.String DEFAULT_DATE_FORMAT
The default date format of "MMMM d, yyyy"

See Also:
Constant Field Values

DATE_FORMAT_MMM_D_YYYY

public static final java.lang.String DATE_FORMAT_MMM_D_YYYY
The date format of "MMMM d, yyyy"

See Also:
Constant Field Values

DATE_FORMAT_DD_MMM_YYYY

public static final java.lang.String DATE_FORMAT_DD_MMM_YYYY
The date format of "dd MMM yyyy"

See Also:
Constant Field Values

DEFAULT_TIME_FORMAT

public static final java.lang.String DEFAULT_TIME_FORMAT
The default time format of "MMM d, yyyy h:mm:ss a"

See Also:
Constant Field Values

TIME_FORMAT_MMM_D_YYYY_H_MM_A

public static final java.lang.String TIME_FORMAT_MMM_D_YYYY_H_MM_A
The time format of "MMM d, yyyy h:mm a"

See Also:
Constant Field Values
Constructor Detail

DateUtils

public DateUtils()
Method Detail

formatDate

public static java.lang.String formatDate(java.util.Date date)
Formats the passed in date with the default format and returns it as a String.

Parameters:
date - The date to format as a 'Date'
Returns:
The formatted date

formatDate

public static java.lang.String formatDate(java.util.Date date,
                                          java.lang.String format)
Formats the passed in date and returns it as a String. The default format will be used if no format is passed in.

Parameters:
date - The date to format as a 'Date'
format - The date format to use.
Returns:
The formatted date

formatTime

public static java.lang.String formatTime(java.util.Date date)
Formats the passed in date/time with the default format and returns it as a String.

Parameters:
date - The date to format as a 'Time'
Returns:
The formatted date/time

formatTime

public static java.lang.String formatTime(java.util.Date date,
                                          java.lang.String format)
Formats the passed in date/time and returns it as a String. The default format will be used if no format is passed in.

Parameters:
date - The date to format as a 'Time'
format - The time format to use.
Returns:
The formatted date/time

formatTime

public static java.lang.String formatTime(java.util.Calendar calendar)
Formats the passed in date/time and returns it as a String.

Parameters:
calendar - The date to format as a 'Calendar'
Returns:
The formatted date/time

formatElapsedTime

public static java.lang.String formatElapsedTime(long elapsedTime,
                                                 boolean displayMilliseconds)
Formats an elapsed period of time in milliseconds.

Parameters:
elapsedTime - The elapsed time in millilseconds to format
displayMilliseconds - Whether to display milliseconds or not
Returns:
The formatted elapsed time.

startTimer

public static java.lang.String startTimer()
Starts a timer and returns a key to this timer. The timer can be stopped by using the stopTimer method and elapsed time can be obtained at various times using the getElapsedTime method. The returned key should be used as a parameter to the stopTimer and getElapsedTime methods. Note that the key returned is a string representing the current date/time and can be used for displaying purposes.

Returns:
The key for this timer

getElapsedTime

public static long getElapsedTime(java.lang.String key)
Get elapsed time from a previously started timer. The elapsed time is based on a key obtained from the startTimer method. This method can be called many times to get the elapsed time from a given start point if desired. To stop the timer, use the stopTimer method.

Parameters:
key - The key for the started timer.
Returns:
The time in milliseconds since the timer was first started. -1 is returned if the passed in key is invalid.

getElapsedDays

public static long getElapsedDays(java.util.Calendar startTime,
                                  java.util.Calendar endTime)
Gets the elapsed number of days between the start and end times.

Parameters:
startTime - the start time.
endTime - the end time.
Returns:
the elapsed number of days.

getElapsedDays

public static long getElapsedDays(long elapsedTime)
Gets the elapsed number of days given the elapsed miliseconds.

Parameters:
elapsedTime - the elapsed number of miliseconds.
Returns:
the elapsed number of days.

stopTimer

public static long stopTimer(java.lang.String key)
Stops a previously started timer. The timer to stop is identified by the key which is passed in. This key can be obtained from the startTimer method. Once the stopTimer method is called, the key is no longer valid.

Parameters:
key - The key for the started timer.
Returns:
The time in milliseconds since the timer was first started. -1 is returned if the passed in key is invalid.

getMonth

public static int getMonth(java.lang.String month)
                    throws java.text.ParseException
Get the integer month based on the spelled out month. The full month name as well as the abbreviation can be passed in (e.g. Jan and January will both work and will return 1).

Parameters:
month - The month to get the integer from.
Returns:
The integer version of the month.
Throws:
java.text.ParseException - if the month wasn't recognized

getCurrentDayAtMidnight

public static java.util.Calendar getCurrentDayAtMidnight()
Gets the current date at midnight.

Returns:
The current date at midnight.

getMonth

public static java.lang.String getMonth(int month)
                                 throws java.lang.IllegalArgumentException
Gets the string month based on the passed in integer month. The fully spelled out month name is returned (e.g. 1 will return January).

Parameters:
month - The month
Returns:
The string version of the month.
Throws:
java.lang.IllegalArgumentException - if the month is out of range

formatCalendar

public static java.lang.String formatCalendar(java.util.Calendar calendar)
Formats the passed in calendar into a dd-MMM-yyyy HH:mm:ss format.

Parameters:
calendar - The calendar to format
Returns:
The formatted calendar string or the empty string if null was passed in.

formatCalendar

public static java.lang.String formatCalendar(java.util.Calendar calendar,
                                              java.lang.String format)
Formats the passed in calendar into the format specified.

Parameters:
calendar - The calendar to format
format - The format.
Returns:
The formatted calendar string or the empty string if null was passed in.

getCalendarUsingFormat

public static java.util.Calendar getCalendarUsingFormat(java.lang.String dateString,
                                                        java.lang.String dateFormat)
Gets a Calendar from the passed in date as a String.

Parameters:
dateString - The date in the format of a String.
dateFormat - The format of the date pattern. If no pattern was specified, the default MM/dd/yyyy HH:mm:ss will be used.
Returns:
The parsed calendar.
Throws:
java.lang.IllegalArgumentException - if the date or format is invalid.

getCalendarUsingFormats

public static java.util.Calendar getCalendarUsingFormats(java.lang.String dateString,
                                                         java.lang.String[] dateFormats)
Gets a Calendar from the passed in date as a String.

Parameters:
dateString - The date in the format of a String.
dateFormats - The array of date formats. If this parameter is null, the following two formats will be used: "MM/dd/yyyy" and "MM/dd/yyyy HH:mm:ss".
Returns:
The parsed calendar.
Throws:
java.lang.IllegalArgumentException - if the date or format is invalid.


Copyright © 2005-2008 Fox Smart, Inc. All Rights Reserved.