Example usage for java.util Calendar before

List of usage examples for java.util Calendar before

Introduction

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

Prototype

public boolean before(Object when) 

Source Link

Document

Returns whether this Calendar represents a time before the time represented by the specified Object.

Usage

From source file:Main.java

public static void main(String[] args) {
    Calendar old = Calendar.getInstance();
    old.set(Calendar.YEAR, 2990);
    Calendar now = Calendar.getInstance();
    System.out.println("Is old before now ? : " + old.before(now));

}

From source file:fr.itinerennes.bundler.integration.onebusaway.GenerateStaticObaApiResults.java

public static void main(String[] args) throws IOException, GtfsException {

    final String url = args[0];
    final String key = args[1];
    final String gtfsFile = args[2];
    final String out = args[3].replaceAll("/$", "");

    final Map<String, String> agencyMapping = new HashMap<String, String>();
    agencyMapping.put("1", "2");
    final GtfsDao gtfs = GtfsUtils.load(new File(gtfsFile), agencyMapping);

    oba = new JsonOneBusAwayClient(new DefaultHttpClient(), url, key);
    gson = OneBusAwayGsonFactory.newInstance(true);

    final Calendar end = Calendar.getInstance();
    end.set(2013, 11, 22, 0, 0);//from  w w  w  .ja  v  a  2  s.  c  o m

    final Calendar start = Calendar.getInstance();
    start.set(2013, 10, 4, 0, 0);

    final Calendar current = Calendar.getInstance();
    current.setTime(start.getTime());

    while (current.before(end) || current.equals(end)) {
        System.out.println(current.getTime());
        for (final Stop stop : gtfs.getAllStops()) {
            final String stopId = stop.getId().toString();
            final String dateDir = String.format("%04d/%02d/%02d", current.get(Calendar.YEAR),
                    current.get(Calendar.MONTH) + 1, current.get(Calendar.DAY_OF_MONTH));
            final String methodDir = String.format("%s/schedule-for-stop", out);

            final File outDir = new File(String.format("%s/%s", methodDir, dateDir));
            outDir.mkdirs();
            final File f = new File(outDir, String.format("%s.json", stopId));

            final StopSchedule ss = oba.getScheduleForStop(stopId, current.getTime());
            final String json = gson.toJson(ss);

            final Writer w = new PrintWriter(f);
            w.write(json);
            w.close();
        }
        current.add(Calendar.DAY_OF_MONTH, 1);
    }

    final File outDir = new File(String.format("%s/trip-details", out));
    outDir.mkdirs();
    for (final Trip trip : gtfs.getAllTrips()) {
        final String tripId = trip.getId().toString();
        final File f = new File(outDir, String.format("%s.json", tripId));

        final TripSchedule ts = oba.getTripDetails(tripId);
        final String json = gson.toJson(ts);

        final Writer w = new PrintWriter(f);
        w.write(json);
        w.close();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyy");
    Date date1 = sdf.parse("Thu Oct 03 07:47:22 2015");
    Date date2 = sdf.parse("Mon Jul 05 08:47:22 2015");

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

    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    cal1.setTime(date1);/* w w  w  .  j a  va2s.c  om*/
    cal2.setTime(date2);

    if (cal1.after(cal2)) {
        System.out.println("Date1 is after Date2");
    }

    if (cal1.before(cal2)) {
        System.out.println("Date1 is before Date2");
    }

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

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();
    Calendar past = Calendar.getInstance();

    System.out.println("Current date: " + cal.getTime());

    // change year in past calendar
    past.set(Calendar.YEAR, 2013);
    System.out.println("Year is " + past.get(Calendar.YEAR));

    // check if calendar date is before current date
    System.out.println(cal.before(past));
}

From source file:com.pureinfo.srm.config.notice.TestTimer.java

public static void main(String[] args) throws ParseException {
    Calendar start = new GregorianCalendar();
    start.setTime(format.parse("18:40"));
    Calendar cal = new GregorianCalendar();
    start.set(Calendar.YEAR, cal.get(Calendar.YEAR));
    start.set(Calendar.MONTH, cal.get(Calendar.MONTH));
    start.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH));
    while (start.before(cal)) {
        start.setTimeInMillis(start.getTimeInMillis() + DateUtils.MILLIS_PER_MINUTE);
    }/*from   ww w. j a v a2  s.c o  m*/
    new Timer().scheduleAtFixedRate(new test1(), start.getTime(), DateUtils.MILLIS_PER_MINUTE);
}

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  . co 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

private static long countDays(Calendar start, Calendar end) {
    long totalNumberOfDays = 0;
    while (start.before(end)) {
        start.add(Calendar.DAY_OF_MONTH, 1);
        totalNumberOfDays++;//  w w  w  . j  a v a2s  .c o  m
    }
    return totalNumberOfDays;
}

From source file:Main.java

public static boolean dataEhMenorOuIgual(Calendar data, Calendar dataFinalCiclo) {
    return data.before(dataFinalCiclo) || data.compareTo(dataFinalCiclo) == 0;
}

From source file:Main.java

public static Calendar addDaysIfBefore(Calendar date, Calendar dateBefore, int daysToAdd) {
    while (date.before(dateBefore)) {
        date.add(Calendar.DAY_OF_MONTH, daysToAdd);
    }//  ww  w.j ava 2 s .  com

    return date;
}

From source file:Main.java

public static int daysBetween(Calendar startDate, Calendar endDate) {

    Calendar date = (Calendar) startDate.clone();
    long daysBetween = 0;
    while (date.before(endDate)) {
        date.add(Calendar.DAY_OF_MONTH, 1);
        daysBetween++;//from w w w  . java 2s .  co  m
    }
    return (int) (daysBetween / 365.25);
}