com.sibvisions.util.type
Class DateUtil

java.lang.Object
  extended by com.sibvisions.util.type.DateUtil

public class DateUtil
extends Object

The DateUtil is a utility class for date conversion and for formatting dates as string.


Constructor Summary
DateUtil()
          Constructs a new instance of DateUtil with default date format.
DateUtil(DateFormat pDateFormat)
          Constructs a new instance of DateUtil that supports empty Strings and null values.
DateUtil(String pDatePattern)
          Constructs a new instance of DateUtil that supports empty Strings and null values.
 
Method Summary
static Date convert(Date pDate, String pFromTimeZone, String pToTimeZone)
          Converts a date from one timezone to another timezone.
static Date convert(Date pDate, TimeZone pFromTimeZone, TimeZone pToTimeZone)
          Converts a date from one timezone to another timezone.
 String format(Date pDate)
          Formats the date to text.
static String format(Date pDate, String pFormat)
          Formats a Date into a date/time string.
static String format(long pDate, String pFormat)
          Formats a time string.
static Date getDate(int pDay, int pMonth, int pYear, int pHour, int pMinutes, int pSeconds)
          Creates a new date instance.
 DateFormat getDateFormat()
          Gets the date format.
 String getDatePattern()
          Gets the date format pattern.
 boolean isStrictFormatCheck()
          Strict format check defines whether the set pattern should be exactly by format, or be more flexibel in analysing the given date.
 Date parse(String pText)
          Parses the date from text.
 void setDateFormat(DateFormat pDateFormat)
          Gets the date format.
 void setDatePattern(String pDatePattern)
          Gets the date format pattern.
 void setStrictFormatCheck(boolean pStrictFormatCheck)
          Strict format check defines whether the set pattern should be exactly by format, or be more flexibel in analysing the given date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateUtil

public DateUtil()
Constructs a new instance of DateUtil with default date format.


DateUtil

public DateUtil(DateFormat pDateFormat)
Constructs a new instance of DateUtil that supports empty Strings and null values.

Parameters:
pDateFormat - the formatter that should support empty Strings and null values

DateUtil

public DateUtil(String pDatePattern)
Constructs a new instance of DateUtil that supports empty Strings and null values.

Parameters:
pDatePattern - the pattern that should support empty Strings and null values
Method Detail

parse

public Date parse(String pText)
           throws ParseException
Parses the date from text.

Parameters:
pText - the text.
Returns:
the parsed date.
Throws:
ParseException - if there is an error in the conversion

format

public String format(Date pDate)
Formats the date to text.

Parameters:
pDate - the date.
Returns:
the formatted text.

getDateFormat

public DateFormat getDateFormat()
Gets the date format.

Returns:
the date format.

setDateFormat

public void setDateFormat(DateFormat pDateFormat)
Gets the date format.

Parameters:
pDateFormat - the date format.

getDatePattern

public String getDatePattern()
Gets the date format pattern.

Returns:
the date format pattern.

setDatePattern

public void setDatePattern(String pDatePattern)
Gets the date format pattern.

Parameters:
pDatePattern - the date format pattern.

isStrictFormatCheck

public boolean isStrictFormatCheck()
Strict format check defines whether the set pattern should be exactly by format, or be more flexibel in analysing the given date. This has nothing to do with lenient in SimpleDateFormat. Lenient is set to false anyway. Only correct dates are allowed. The following will be allowed without strict check, with locale de_AT and pattern: dd. MMMM.yyyy HH:mm 01.01.2016 01.Januar.2016 00:00 01.Jänner.2016 01.01 01.01.16 01.01 01 01 2016 00 00 010116 01012016 The result will always be 01.Januar.2016 00:00

Returns:
true, if format should be checked strict.

setStrictFormatCheck

public void setStrictFormatCheck(boolean pStrictFormatCheck)
Strict format check defines whether the set pattern should be exactly by format, or be more flexibel in analysing the given date. This has nothing to do with lenient in SimpleDateFormat. Lenient is set to false anyway. Only correct dates are allowed. The following will be allowed without strict check, with locale de_AT and pattern: dd. MMMM.yyyy HH:mm 01.01.2016 01.Januar.2016 00:00 01.Jänner.2016 01.01 01.01.16 01.01 01 01 2016 00 00 010116 01012016 The result will always be 01.Januar.2016 00:00

Parameters:
pStrictFormatCheck - true, if format should be checked strict.

format

public static String format(long pDate,
                            String pFormat)
Formats a time string.

Parameters:
pDate - the time (in millis since 01.01.1970 00:00) value to be formatted into a time string
pFormat - the format
Returns:
the formatted date/time string
See Also:
SimpleDateFormat

format

public static String format(Date pDate,
                            String pFormat)
Formats a Date into a date/time string.

Parameters:
pDate - the time value to be formatted into a time string
pFormat - the format
Returns:
the formatted date/time string
See Also:
SimpleDateFormat

getDate

public static Date getDate(int pDay,
                           int pMonth,
                           int pYear,
                           int pHour,
                           int pMinutes,
                           int pSeconds)
Creates a new date instance.

Parameters:
pDay - the day of month
pMonth - the month
pYear - the year
pHour - the hour of day
pMinutes - the minutes
pSeconds - the seconds
Returns:
the date

convert

public static Date convert(Date pDate,
                           String pFromTimeZone,
                           String pToTimeZone)
Converts a date from one timezone to another timezone.

Parameters:
pDate - the date
pFromTimeZone - the timezone of the date
pToTimeZone - the expected timezone
Returns:
the date converted to the expected timezone

convert

public static Date convert(Date pDate,
                           TimeZone pFromTimeZone,
                           TimeZone pToTimeZone)
Converts a date from one timezone to another timezone.

Parameters:
pDate - the date
pFromTimeZone - the timezone of the date
pToTimeZone - the expected timezone
Returns:
the date converted to the expected timezone


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.