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

booleancheckDateInToday(Date date)
check Date In Today
if (date == null) {
    return true;
boolean flag = false;
Date now = new Date();
String nowStr = dateToString(now, "yyyy-MM-dd");
String dateStr = dateToString(date, "yyyy-MM-dd");
if (!nowStr.equals(dateStr)) {
...
booleancheckDateRange(String fromDate, String endDate)
Check between date range.
long fromTime = transDate(fromDate, "yyyy-MM-dd").getTime();
long endTime = transDate(endDate, "yyyy-MM-dd").getTime();
long todayTime = transDate(getDate(), "yyyy-MM-dd").getTime();
if (fromTime <= todayTime && todayTime <= endTime) {
    return true;
return false;
booleancheckDateValidity(String str, String formatString)
check Date Validity
SimpleDateFormat sdf = new SimpleDateFormat(formatString);
sdf.setLenient(false);
try {
    sdf.parse(str);
    return true;
} catch (ParseException e) {
    return false;
StringcheckTime(int id)
Check time.
String bol = "";
Calendar tt = Calendar.getInstance();
String currDate = getNowDate();
System.out.println("currDate=" + currDate);
int result = tt.get(Calendar.DAY_OF_WEEK);
int shour = tt.get(Calendar.HOUR_OF_DAY);
if (id == 3) {
    switch (result) {
...
booleancheckTimestamp(String timestamp)
check Timestamp
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
Date time = null;
try {
    time = dateFormat.parse(timestamp);
} catch (ParseException e) {
    System.out.println("Timestamp check error");
    e.printStackTrace();
    System.exit(-1);
...