public class DateUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.text.SimpleDateFormat |
DATE_FORMAT |
private static java.text.SimpleDateFormat |
TIMESTAMP_FORMAT |
Constructor and Description |
---|
DateUtil() |
Modifier and Type | Method and Description |
---|---|
static java.util.Date |
copy(java.util.Date value)
Get a copy of the date.
|
static java.lang.String |
formatDate(java.util.Date d)
Formats a date in yyyy-MM-dd format.
|
static java.lang.String |
formatTimestamp(java.util.Date d)
Formats a timestamp in yyyy-MM-dd HH:mm:ss format.
|
static java.util.Date |
parseString(java.lang.String value)
Parses a string to create a
Date without time. |
static java.util.Date |
parseTimestamp(java.lang.String value)
Parses a string to create a
Date including time. |
static java.util.Date |
setNotNullDate(java.util.Date value,
java.lang.String name)
Make a copy of a
Date object. |
static java.util.Date |
setNullableDate(java.util.Date value,
java.lang.String name)
Make a copy of a
Date object. |
static java.util.Date |
truncate(java.util.Date value)
Truncate the given date so that only the date part
remains.
|
private static final java.text.SimpleDateFormat DATE_FORMAT
private static final java.text.SimpleDateFormat TIMESTAMP_FORMAT
public static java.util.Date setNullableDate(java.util.Date value, java.lang.String name)
Date
object. Null values are allowed.value
- The date to checkname
- The name of the attribute to use if an exception is thrownpublic static java.util.Date setNotNullDate(java.util.Date value, java.lang.String name) throws InvalidUseOfNullException
Date
object. Null values are not allowed.value
- The date to check. Can not be null.name
- The name of the attribute to use if an exception is thrownInvalidUseOfNullException
- If the value parameter is null.public static java.util.Date copy(java.util.Date value)
value
- Date value to copypublic static java.util.Date truncate(java.util.Date value)
value
- The date to truncate, can be nullpublic static java.util.Date parseString(java.lang.String value) throws InvalidDataException
Date
without time. This method supports
date in yyyy-MM-dd format or as long timevalues.value
- the String
to be parsedDate
objectDateFormatException
- if value
isn't a valid date.InvalidDataException
public static java.lang.String formatDate(java.util.Date d)
d
- The date to format.public static java.util.Date parseTimestamp(java.lang.String value) throws InvalidDataException
Date
including time. This method
supports date in yyyy-MM-dd HH:mm:ss format or as long timevalues.value
- the String
to be parsedDate
objectDateFormatException
- if value
isn't a valid timestampInvalidDataException
public static java.lang.String formatTimestamp(java.util.Date d)
d
- The date to format.