gnu.caf.util
Class DateUtil

java.lang.Object
  extended by gnu.caf.util.DateUtil

public class DateUtil
extends java.lang.Object

Date 타입의 처리를 위한 유틸클래스.


Field Summary
static java.lang.String BUNDLE_KEY
          The name of the ResourceBundle used in this application
static int MILLIS_IN_DAY
          Deprecated. Use MILLIS_PER_DAY. This will be removed in Commons Lang 3.0.
static int MILLIS_IN_HOUR
          Deprecated. Use MILLIS_PER_HOUR. This will be removed in Commons Lang 3.0.
static int MILLIS_IN_MINUTE
          Deprecated. Use MILLIS_PER_MINUTE. This will be removed in Commons Lang 3.0.
static int MILLIS_IN_SECOND
          Deprecated. Use MILLIS_PER_SECOND. This will be removed in Commons Lang 3.0.
static long MILLIS_PER_DAY
           
static long MILLIS_PER_HOUR
           
static long MILLIS_PER_MINUTE
           
static long MILLIS_PER_SECOND
           
static int RANGE_MONTH_MONDAY
          A month range, the week starting on Monday.
static int RANGE_MONTH_SUNDAY
          A month range, the week starting on Sunday.
static int RANGE_WEEK_CENTER
          A week range, centered around the day focused.
static int RANGE_WEEK_MONDAY
          A week range, starting on Monday.
static int RANGE_WEEK_RELATIVE
          A week range, starting on the day focused.
static int RANGE_WEEK_SUNDAY
          A week range, starting on Sunday.
static int SEMI_MONTH
           
static java.util.TimeZone UTC_TIME_ZONE
           
 
Constructor Summary
DateUtil()
          DateUtils instances should NOT be constructed in standard programming.
 
Method Summary
static java.lang.String convertDateToString(java.util.Date aDate)
          This method generates a string representation of a date based on the System Property 'dateFormat' in the format you specify on input
static java.util.Date convertStringToDate(java.lang.String strDate)
          This method converts a String to a date using the datePattern
static java.util.Date convertStringToDate(java.lang.String aMask, java.lang.String strDate)
          This method generates a string representation of a date/time in the format you specify on input
static java.lang.String getCurrentDate()
           
static java.lang.String getCurrentDate(java.lang.String format)
           
static java.lang.String getCurrentMonth01()
           
static java.lang.String getCurrentMonth31()
           
static java.lang.String getCurrentYear()
           
static java.lang.String getDate(java.util.Date aDate)
          This method attempts to convert an Oracle-formatted date in the form dd-MMM-yyyy to mm/dd/yyyy.
static java.lang.String getDate(java.util.Date date, java.lang.String format)
           
static java.lang.String getDate(int day)
           
static java.lang.String getDate(int day, java.lang.String format)
           
static java.lang.String getDatePattern()
          Return default datePattern (MM/dd/yyyy)
static java.lang.String getDateTime(java.lang.String aMask, java.util.Date aDate)
          This method generates a string representation of a date's date/time in the format you specify on input
static java.lang.String getTimeNow(java.util.Date theTime)
          This method returns the current date time in the format: MM/dd/yyyy HH:MM a
static java.util.Calendar getToday()
          This method returns the current date in the format: MM/dd/yyyy
static boolean isSameDay(java.util.Calendar cal1, java.util.Calendar cal2)
          Checks if two calendar objects are on the same day ignoring time.
static boolean isSameDay(java.util.Date date1, java.util.Date date2)
          Checks if two date objects are on the same day ignoring time.
static boolean isSameInstant(java.util.Calendar cal1, java.util.Calendar cal2)
          Checks if two calendar objects represent the same instant in time.
static boolean isSameInstant(java.util.Date date1, java.util.Date date2)
          Checks if two date objects represent the same instant in time.
static boolean isSameLocalTime(java.util.Calendar cal1, java.util.Calendar cal2)
          Checks if two calendar objects represent the same local time.
static java.util.Iterator iterator(java.util.Calendar focus, int rangeStyle)
          This constructs an Iterator that will start and stop over a date range based on the focused date and the range style.
static java.util.Iterator iterator(java.util.Date focus, int rangeStyle)
          This constructs an Iterator that will start and stop over a date range based on the focused date and the range style.
static java.util.Iterator iterator(java.lang.Object focus, int rangeStyle)
          This constructs an Iterator that will start and stop over a date range based on the focused date and the range style.
static java.util.Date parseDate(java.lang.String str, java.lang.String[] parsePatterns)
          Parses a string representing a date by trying a variety of different parsers.
static java.util.Calendar round(java.util.Calendar date, int field)
          Round this date, leaving the field specified as the most significant field.
static java.util.Date round(java.util.Date date, int field)
          Round this date, leaving the field specified as the most significant field.
static java.util.Date round(java.lang.Object date, int field)
          Round this date, leaving the field specified as the most significant field.
static java.util.Calendar truncate(java.util.Calendar date, int field)
          Truncate this date, leaving the field specified as the most significant field.
static java.util.Date truncate(java.util.Date date, int field)
          Truncate this date, leaving the field specified as the most significant field.
static java.util.Date truncate(java.lang.Object date, int field)
          Truncate this date, leaving the field specified as the most significant field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UTC_TIME_ZONE

public static final java.util.TimeZone UTC_TIME_ZONE

MILLIS_PER_SECOND

public static final long MILLIS_PER_SECOND
See Also:
Constant Field Values

MILLIS_PER_MINUTE

public static final long MILLIS_PER_MINUTE
See Also:
Constant Field Values

MILLIS_PER_HOUR

public static final long MILLIS_PER_HOUR
See Also:
Constant Field Values

MILLIS_PER_DAY

public static final long MILLIS_PER_DAY
See Also:
Constant Field Values

SEMI_MONTH

public static final int SEMI_MONTH
See Also:
Constant Field Values

BUNDLE_KEY

public static final java.lang.String BUNDLE_KEY
The name of the ResourceBundle used in this application

See Also:
Constant Field Values

RANGE_WEEK_SUNDAY

public static final int RANGE_WEEK_SUNDAY
A week range, starting on Sunday.

See Also:
Constant Field Values

RANGE_WEEK_MONDAY

public static final int RANGE_WEEK_MONDAY
A week range, starting on Monday.

See Also:
Constant Field Values

RANGE_WEEK_RELATIVE

public static final int RANGE_WEEK_RELATIVE
A week range, starting on the day focused.

See Also:
Constant Field Values

RANGE_WEEK_CENTER

public static final int RANGE_WEEK_CENTER
A week range, centered around the day focused.

See Also:
Constant Field Values

RANGE_MONTH_SUNDAY

public static final int RANGE_MONTH_SUNDAY
A month range, the week starting on Sunday.

See Also:
Constant Field Values

RANGE_MONTH_MONDAY

public static final int RANGE_MONTH_MONDAY
A month range, the week starting on Monday.

See Also:
Constant Field Values

MILLIS_IN_SECOND

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.

See Also:
Constant Field Values

MILLIS_IN_MINUTE

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.

See Also:
Constant Field Values

MILLIS_IN_HOUR

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.

See Also:
Constant Field Values

MILLIS_IN_DAY

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.

See Also:
Constant Field Values
Constructor Detail

DateUtil

public DateUtil()

DateUtils instances should NOT be constructed in standard programming. Instead, the class should be used as DateUtils.parse(str);.

This constructor is public to permit tools that require a JavaBean instance to operate.

Method Detail

getDatePattern

public static java.lang.String getDatePattern()
Return default datePattern (MM/dd/yyyy)

Returns:
a string representing the date pattern on the UI

getDate

public static final java.lang.String getDate(java.util.Date aDate)
This method attempts to convert an Oracle-formatted date in the form dd-MMM-yyyy to mm/dd/yyyy.

Parameters:
aDate - date from database as a string
Returns:
formatted string for the ui

getDate

public static java.lang.String getDate(java.util.Date date,
                                       java.lang.String format)

convertStringToDate

public static final java.util.Date convertStringToDate(java.lang.String aMask,
                                                       java.lang.String strDate)
                                                throws java.text.ParseException
This method generates a string representation of a date/time in the format you specify on input

Parameters:
aMask - the date pattern the string is in
strDate - a string representation of a date
Returns:
a converted Date object
Throws:
java.text.ParseException
See Also:
SimpleDateFormat

getTimeNow

public static java.lang.String getTimeNow(java.util.Date theTime)
This method returns the current date time in the format: MM/dd/yyyy HH:MM a

Parameters:
theTime - the current time
Returns:
the current date/time

getToday

public static java.util.Calendar getToday()
                                   throws java.text.ParseException
This method returns the current date in the format: MM/dd/yyyy

Returns:
the current date
Throws:
java.text.ParseException

getDateTime

public static final java.lang.String getDateTime(java.lang.String aMask,
                                                 java.util.Date aDate)
This method generates a string representation of a date's date/time in the format you specify on input

Parameters:
aMask - the date pattern the string is in
aDate - a date object
Returns:
a formatted string representation of the date
See Also:
SimpleDateFormat

convertDateToString

public static final java.lang.String convertDateToString(java.util.Date aDate)
This method generates a string representation of a date based on the System Property 'dateFormat' in the format you specify on input

Parameters:
aDate - A date to convert
Returns:
a string representation of the date

convertStringToDate

public static java.util.Date convertStringToDate(java.lang.String strDate)
                                          throws java.text.ParseException
This method converts a String to a date using the datePattern

Parameters:
strDate - the date to convert (in format MM/dd/yyyy)
Returns:
a date object
Throws:
java.text.ParseException

getCurrentMonth01

public static java.lang.String getCurrentMonth01()

getCurrentMonth31

public static java.lang.String getCurrentMonth31()

getCurrentDate

public static java.lang.String getCurrentDate(java.lang.String format)

getCurrentDate

public static java.lang.String getCurrentDate()

getCurrentYear

public static java.lang.String getCurrentYear()

getDate

public static java.lang.String getDate(int day)

getDate

public static java.lang.String getDate(int day,
                                       java.lang.String format)

isSameDay

public static boolean isSameDay(java.util.Date date1,
                                java.util.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 null
date2 - the second date, not altered, not null
Returns:
true if they represent the same day
Throws:
java.lang.IllegalArgumentException - if either date is null
Since:
2.1

isSameDay

public static boolean isSameDay(java.util.Calendar cal1,
                                java.util.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 null
cal2 - the second calendar, not altered, not null
Returns:
true if they represent the same day
Throws:
java.lang.IllegalArgumentException - if either calendar is null
Since:
2.1

isSameInstant

public static boolean isSameInstant(java.util.Date date1,
                                    java.util.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 null
date2 - the second date, not altered, not null
Returns:
true if they represent the same millisecond instant
Throws:
java.lang.IllegalArgumentException - if either date is null
Since:
2.1

isSameInstant

public static boolean isSameInstant(java.util.Calendar cal1,
                                    java.util.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 null
cal2 - the second calendar, not altered, not null
Returns:
true if they represent the same millisecond instant
Throws:
java.lang.IllegalArgumentException - if either date is null
Since:
2.1

isSameLocalTime

public static boolean isSameLocalTime(java.util.Calendar cal1,
                                      java.util.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 null
cal2 - the second calendar, not altered, not null
Returns:
true if they represent the same millisecond instant
Throws:
java.lang.IllegalArgumentException - if either date is null
Since:
2.1

parseDate

public static java.util.Date parseDate(java.lang.String str,
                                       java.lang.String[] parsePatterns)
                                throws java.text.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 null
parsePatterns - the date format patterns to use, see SimpleDateFormat, not null
Returns:
the parsed date
Throws:
java.lang.IllegalArgumentException - if the date string or pattern array is null
java.text.ParseException - if none of the date patterns were suitable

round

public static java.util.Date round(java.util.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:

Parameters:
date - the date to work with
field - the field from Calendar or SEMI_MONTH
Returns:
the rounded date
Throws:
java.lang.IllegalArgumentException - if the date is null
java.lang.ArithmeticException - if the year is over 280 million

round

public static java.util.Calendar round(java.util.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:

Parameters:
date - the date to work with
field - the field from Calendar or SEMI_MONTH
Returns:
the rounded date (a different object)
Throws:
java.lang.IllegalArgumentException - if the date is null
java.lang.ArithmeticException - if the year is over 280 million

round

public static java.util.Date round(java.lang.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:

Parameters:
date - the date to work with, either Date or Calendar
field - the field from Calendar or SEMI_MONTH
Returns:
the rounded date
Throws:
java.lang.IllegalArgumentException - if the date is null
java.lang.ClassCastException - if the object type is not a Date or Calendar
java.lang.ArithmeticException - if the year is over 280 million

truncate

public static java.util.Date truncate(java.util.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 with
field - the field from Calendar or SEMI_MONTH
Returns:
the rounded date
Throws:
java.lang.IllegalArgumentException - if the date is null
java.lang.ArithmeticException - if the year is over 280 million

truncate

public static java.util.Calendar truncate(java.util.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 with
field - the field from Calendar or SEMI_MONTH
Returns:
the rounded date (a different object)
Throws:
java.lang.IllegalArgumentException - if the date is null
java.lang.ArithmeticException - if the year is over 280 million

truncate

public static java.util.Date truncate(java.lang.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, either Date or Calendar
field - the field from Calendar or SEMI_MONTH
Returns:
the rounded date
Throws:
java.lang.IllegalArgumentException - if the date is null
java.lang.ClassCastException - if the object type is not a Date or Calendar
java.lang.ArithmeticException - if the year is over 280 million

iterator

public static java.util.Iterator iterator(java.util.Date focus,
                                          int rangeStyle)

This constructs an Iterator 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 a RANGE_MONTH_SUNDAY will return an Iterator that starts with Sunday, June 30, 2002 and ends with Saturday, August 3, 2002.

Parameters:
focus - the date to work with
rangeStyle - the style constant to use. Must be one of the range styles listed for the iterator(Calendar, int) method.
Returns:
the date iterator
Throws:
java.lang.IllegalArgumentException - if the date is null or if the rangeStyle is not

iterator

public static java.util.Iterator iterator(java.util.Calendar focus,
                                          int rangeStyle)

This constructs an Iterator 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 a RANGE_MONTH_SUNDAY will return an Iterator that starts with Sunday, June 30, 2002 and ends with Saturday, August 3, 2002.

Parameters:
focus - the date to work with
rangeStyle - the style constant to use. Must be one of
Returns:
the date iterator
Throws:
java.lang.IllegalArgumentException - if the date is null

iterator

public static java.util.Iterator iterator(java.lang.Object focus,
                                          int rangeStyle)

This constructs an Iterator 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 a RANGE_MONTH_SUNDAY will return an Iterator that starts with Sunday, June 30, 2002 and ends with Saturday, August 3, 2002.

Parameters:
focus - the date to work with, either Date or Calendar
rangeStyle - the style constant to use. Must be one of the range styles listed for the iterator(Calendar, int) method.
Returns:
the date iterator
Throws:
java.lang.IllegalArgumentException - if the date is null
java.lang.ClassCastException - if the object type is not a Date or Calendar


Copyright © 2003 All Rights Reserved.