Java Utililty Methods Date Format Check

List of utility methods to do Date Format Check

Description

The list of methods to do Date Format Check are organized into topic(s).

Method

StringcheckDate(Date date)
Dates handler.
if (date == null) {
    return ""; 
DateFormat formatter = DateFormat.getDateTimeInstance();
return formatter.format(date);
booleancheckDate(String begingDate, String endDate)
check Date
boolean boo = true;
Date begin = null;
Date end = null;
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
if (null == begingDate || "".equals(begingDate)) {
    boo = false;
    return boo;
if (null == endDate || "".equals(endDate)) {
    boo = false;
    return boo;
try {
    begin = df.parse(begingDate);
    end = df.parse(endDate);
} catch (ParseException e) {
    e.printStackTrace();
if (begin.compareTo(end) >= 0) {
    boo = false;
return boo;
booleancheckDate(String deadline)
check Date
SimpleDateFormat sdf;
sdf = new SimpleDateFormat(DISPLAY_DATE_FORMAT, java.util.Locale.US);
sdf.setLenient(false);
try {
    sdf.parse(deadline);
} catch (ParseException e) {
    return false;
return true;
IntegercheckDateBetween(String time)
check Date Between
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse(time);
long diff = date.getTime() - new Date().getTime();
long diffHours = diff / (60 * 60 * 1000);
long diffMinutes = diff / (60 * 1000) % 60;
int mins = (int) (diffHours * 60 + diffMinutes);
return mins;
booleancheckDateByMask(String sDateValue, String sDateFormat)
check the date by pattern
boolean isTrue = false;
if (sDateValue == null || sDateFormat == null || sDateValue.equals(""))
    return false;
if (sDateValue.length() != sDateFormat.length())
    return false;
java.util.Date date = stringToDate(sDateValue, sDateFormat);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
...
voidcheckDateFormat()
check Date Format
if (dateFormat == null) {
    dateFormat = new SimpleDateFormat(DATE_FORMAT);
voidcheckDateFormat()
check Date Format
if (_dateFormat == null) {
    _dateFormat = new SimpleDateFormat(DATE_FORMAT_DEFN);
    _dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    _longTimeFormat = new SimpleDateFormat(LONG_TIME_FORMAT_DEFN);
    _longTimeFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    _shortTimeFormat = new SimpleDateFormat(SHORT_TIME_FORMAT_DEFN);
    _shortTimeFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    _fullFormat = new SimpleDateFormat(DATE_FORMAT_DEFN + "Z" + LONG_TIME_FORMAT_DEFN);
...
voidcheckDateFormat(String pattern)
Checks if the date/time format is valid
new SimpleDateFormat(pattern);
booleancheckDateFormat(String strTime, String pattern)
check Date Format
if (strTime.length() != pattern.trim().length())
    return false;
try {
    SimpleDateFormat sdf = new SimpleDateFormat(pattern.trim());
    sdf.parse(strTime);
} catch (Exception e) {
    return false;
return true;
booleancheckDateFormatAndValite(String strDateTime, String format)
check Date Format And Valite
if (strDateTime == null || strDateTime.length() == 0) {
    return false;
SimpleDateFormat sdf = new SimpleDateFormat(format);
try {
    Date ndate = sdf.parse(strDateTime);
    String str = sdf.format(ndate);
    System.out.println("func<checkDateFormatAndValite> strDateTime<" + strDateTime + "> format<" + format
...