Example usage for java.util Date before

List of usage examples for java.util Date before

Introduction

In this page you can find the example usage for java.util Date before.

Prototype

public boolean before(Date when) 

Source Link

Document

Tests if this date is before the specified date.

Usage

From source file:Main.java

public static void main(String[] args) {
    Date today = new Date();

    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -1);
    Date yesterday = calendar.getTime();

    if (yesterday.before(today)) {
        System.out.println(yesterday + " is before " + today);
    }/*  www.j  a  va2s .  c om*/
}

From source file:Main.java

public static void main(String[] args) {

    Date date = new Date();
    Date date2 = new Date();

    boolean before = date2.before(date);
    System.out.println(before);/*from w w  w .java2  s . c o  m*/

    before = date.before(date2);
    System.out.println(before);
}

From source file:Main.java

public static void main(String[] args) {
    String startDate = "14-08-2014";
    String endDate = "21/08/2020";

    SimpleDateFormat sdf[] = new SimpleDateFormat[] { new SimpleDateFormat("dd/MM/yyyy"),
            new SimpleDateFormat("dd-MM-yyyy") };

    Date dateStart = parse(startDate, sdf);
    Date dateEnd = parse(endDate, sdf);

    System.out.println("Is today bewteen " + dateStart + " and " + dateEnd);
    Date today = new Date();
    if (today.after(dateStart) && today.before(dateEnd)) {
        System.out.println("Yes");
    } else {/*from   w w  w .j a  va2s . c  o m*/
        System.out.println("No");
    }
}

From source file:Main.java

public static void main(String[] args) throws ParseException {

    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");

    String oeStartDateStr = "04/01/2015";
    String oeEndDateStr = "11/14/2015";

    Calendar cal = Calendar.getInstance();
    Integer year = cal.get(Calendar.YEAR);

    oeStartDateStr = oeStartDateStr.concat(year.toString());
    oeEndDateStr = oeEndDateStr.concat(year.toString());

    Date startDate = sdf.parse(oeStartDateStr);
    Date endDate = sdf.parse(oeEndDateStr);
    Date d = new Date();
    String currDt = sdf.format(d);

    if ((d.after(startDate) && (d.before(endDate)))
            || (currDt.equals(sdf.format(startDate)) || currDt.equals(sdf.format(endDate)))) {
        System.out.println("Date is between 1st april to 14th nov...");
    } else {/*from   w w  w  . ja v a  2  s . c o m*/
        System.out.println("Date is not between 1st april to 14th nov...");
    }
}

From source file:MainClass.java

public static void main(String[] a) throws Exception {

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

    Date d1 = df.parse("2001-01-01");

    Date d2 = df.parse("2000-01-01");

    String relation;/*from  w w w.j ava 2 s  .c  o  m*/
    if (d1.equals(d2))
        relation = "the same date as";
    else if (d1.before(d2))
        relation = "before";
    else if (d1.after(d2))
        relation = "after";
    System.out.println(d1 + " is " + relation + ' ' + d2);
}

From source file:CompareDates.java

public static void main(String[] args) throws ParseException {

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

    // Get Date 1
    Date d1 = df.parse("2000-02-01");

    // Get Date 2
    Date d2 = df.parse("2001-03-02");

    String relation;/*from w  w w. ja v  a  2  s .c  o  m*/
    if (d1.equals(d2))
        relation = "the same date as";
    else if (d1.before(d2))
        relation = "before";
    else
        relation = "after";
    System.out.println(d1 + " is " + relation + ' ' + d2);
}

From source file:Main.java

public static void main(String[] args) {
    try {//w ww.java2 s. co  m

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = sdf.parse("2015-12-31");
        Date date2 = sdf.parse("2015-01-31");

        System.out.println(sdf.format(date1));
        System.out.println(sdf.format(date2));

        if (date1.after(date2)) {
            System.out.println("Date1 is after Date2");
        }

        if (date1.before(date2)) {
            System.out.println("Date1 is before Date2");
        }

        if (date1.equals(date2)) {
            System.out.println("Date1 is equal Date2");
        }

    } catch (ParseException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) throws ParseException {
    SimpleDateFormat dateFormat = new SimpleDateFormat("ddMMyyyy");
    Calendar cal = Calendar.getInstance();
    String today = dateFormat.format(cal.getTime());
    System.out.println(today);//from   w  w w. j a  v  a 2  s . c  o  m

    SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy");
    Date actualdate = sdf.parse(today);
    Date date1 = sdf.parse("20042014");
    Date date2 = sdf.parse("23042015");
    Calendar actual = Calendar.getInstance();
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    actual.setTime(actualdate);
    cal1.setTime(date1);
    cal2.setTime(date2);

    System.out.println(actual);
    System.out.println(cal1);
    System.out.println(cal2);

    if (actualdate.after(date1) && actualdate.before(date2)) {
        System.out.println("Yes");
    } else {
        System.out.println("No");
    }

    if (actual.after(cal1) && actual.before(cal2)) {
        System.out.println("Yes");
    } else {
        System.out.println("No");
    }

}

From source file:Main.java

public static boolean isBefore(Date src, Date dst) {
    return src.before(dst);
}

From source file:Main.java

public static boolean isCampaignExpired(Date endDate) {
    return endDate.before(new Date());
}