Java Utililty Methods Second Compare

List of utility methods to do Second Compare

Description

The list of methods to do Second Compare are organized into topic(s).

Method

booleancompareDate(Date firstDate, Date secondDate)
compare Date
if (firstDate == null || secondDate == null) {
    throw new java.lang.RuntimeException();
String strFirstDate = date2String(firstDate, "yyyy-MM-dd");
String strSecondDate = date2String(secondDate, "yyyy-MM-dd");
if (strFirstDate.equals(strSecondDate)) {
    return true;
return false;
intcompareIgnoreSecond(Date date, Date anotherDate)
compare Ignore Second
if (date == null) {
    date = new Date();
if (anotherDate == null) {
    anotherDate = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
...
IntegergetSecondBetweenDate(Date d1, Date d2)
get Second Between Date
Long second = (d2.getTime() - d1.getTime()) / 1000;
return second.intValue();
longgetSecondCa(Date d1, Date d2)
get Second Ca
long quot = Math.abs(d1.getTime() - d2.getTime());
quot = quot / 1000;
return quot;
longgetSecondsOfTowDiffDate(String p_startDate, String p_endDate)
get Seconds Of Tow Diff Date
return (long) getMillisOfTowDiffDate(p_startDate, p_endDate) / 1000;
intsecondBetween(String date)
second Between
SimpleDateFormat sdfSecond = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
    long presentDate = sdfSecond.parse(sdfSecond.format(new Date())).getTime();
    long enterDate = sdfSecond.parse(date).getTime();
    return (int) ((presentDate - enterDate) / 1000);
} catch (ParseException e) {
    e.printStackTrace();
return 1;
longsecondOfDate(Date d1, Date d2)
second Of Date
SimpleDateFormat fDate = new java.text.SimpleDateFormat("yyyyMMddHHmmss");
long l_d1 = Long.valueOf(fDate.format(d1));
long l_d2 = Long.valueOf(fDate.format(d2));
return l_d1 - l_d2;
DatesetSeconds(Date date, int amount)
Sets the seconds field to a date returning a new object.
return set(date, Calendar.SECOND, amount);