Example usage for java.util Date after

List of usage examples for java.util Date after

Introduction

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

Prototype

public boolean after(Date when) 

Source Link

Document

Tests if this date is after 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 tomorrow = calendar.getTime();

    if (tomorrow.after(today)) {
        System.out.println(tomorrow + " is after " + today);
    }// ww  w. j  av a  2 s . c om
}

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 {/* ww  w  .  j  a  v  a 2s.  co 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  .  j a v  a  2s.c o m
        System.out.println("Date is not between 1st april to 14th nov...");
    }
}

From source file:com.heren.turtle.server.utils.SampleDateUtils.java

public static void main(String[] args) {
    Date d1 = new Date();
    Date d2 = new Date();
    System.out.println(d1.after(d2));
    boolean sameDay = DateUtils.isSameDay(d1, d2);
    System.out.println(sameDay);//w  w  w.  j  a  v  a  2 s . c o  m
    System.out.println(addDay("2016-11-16", 3));
}

From source file:Main.java

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

    System.out.println("First Date : " + d1);
    System.out.println("Second Date : " + d2);
    System.out.println("Is second date after first ? : " + d2.after(d1));
}

From source file:Main.java

public static void main(String[] args) {
    Date d1 = Calendar.getInstance().getTime();

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, 2000);
    Date d2 = cal.getTime();

    System.out.println("First Date : " + d1);
    System.out.println("Second Date : " + d2);
    System.out.println("Is second date after first ? : " + d2.after(d1));
}

From source file:Main.java

public static void main(String[] args) {
    try {//  w w w .  j  a v  a 2s  .com

        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: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;//  w w w . j a v  a 2  s  . c  om
    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: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:io.druid.examples.rabbitmq.RabbitMQProducerMain.java

public static void main(String[] args) throws Exception {
    // We use a List to keep track of option insertion order. See below.
    final List<Option> optionList = new ArrayList<Option>();

    optionList.add(OptionBuilder.withLongOpt("help").withDescription("display this help message").create("h"));
    optionList.add(OptionBuilder.withLongOpt("hostname").hasArg()
            .withDescription("the hostname of the AMQP broker [defaults to AMQP library default]").create("b"));
    optionList.add(OptionBuilder.withLongOpt("port").hasArg()
            .withDescription("the port of the AMQP broker [defaults to AMQP library default]").create("n"));
    optionList.add(OptionBuilder.withLongOpt("username").hasArg()
            .withDescription("username to connect to the AMQP broker [defaults to AMQP library default]")
            .create("u"));
    optionList.add(OptionBuilder.withLongOpt("password").hasArg()
            .withDescription("password to connect to the AMQP broker [defaults to AMQP library default]")
            .create("p"));
    optionList.add(OptionBuilder.withLongOpt("vhost").hasArg()
            .withDescription("name of virtual host on the AMQP broker [defaults to AMQP library default]")
            .create("v"));
    optionList.add(OptionBuilder.withLongOpt("exchange").isRequired().hasArg()
            .withDescription("name of the AMQP exchange [required - no default]").create("e"));
    optionList.add(OptionBuilder.withLongOpt("key").hasArg()
            .withDescription("the routing key to use when sending messages [default: 'default.routing.key']")
            .create("k"));
    optionList.add(OptionBuilder.withLongOpt("type").hasArg()
            .withDescription("the type of exchange to create [default: 'topic']").create("t"));
    optionList.add(OptionBuilder.withLongOpt("durable")
            .withDescription("if set, a durable exchange will be declared [default: not set]").create("d"));
    optionList.add(OptionBuilder.withLongOpt("autodelete")
            .withDescription("if set, an auto-delete exchange will be declared [default: not set]")
            .create("a"));
    optionList.add(OptionBuilder.withLongOpt("single")
            .withDescription("if set, only a single message will be sent [default: not set]").create("s"));
    optionList.add(OptionBuilder.withLongOpt("start").hasArg()
            .withDescription("time to use to start sending messages from [default: 2010-01-01T00:00:00]")
            .create());//from  ww  w.java  2  s .  c  om
    optionList.add(OptionBuilder.withLongOpt("stop").hasArg().withDescription(
            "time to use to send messages until (format: '2013-07-18T23:45:59') [default: current time]")
            .create());
    optionList.add(OptionBuilder.withLongOpt("interval").hasArg()
            .withDescription("the interval to add to the timestamp between messages in seconds [default: 10]")
            .create());
    optionList.add(OptionBuilder.withLongOpt("delay").hasArg()
            .withDescription("the delay between sending messages in milliseconds [default: 100]").create());

    // An extremely silly hack to maintain the above order in the help formatting.
    HelpFormatter formatter = new HelpFormatter();
    // Add a comparator to the HelpFormatter using the ArrayList above to sort by insertion order.
    formatter.setOptionComparator(new Comparator() {
        @Override
        public int compare(Object o1, Object o2) {
            // I know this isn't fast, but who cares! The list is short.
            return optionList.indexOf(o1) - optionList.indexOf(o2);
        }
    });

    // Now we can add all the options to an Options instance. This is dumb!
    Options options = new Options();
    for (Option option : optionList) {
        options.addOption(option);
    }

    CommandLine cmd = null;

    try {
        cmd = new BasicParser().parse(options, args);

    } catch (ParseException e) {
        formatter.printHelp("RabbitMQProducerMain", e.getMessage(), options, null);
        System.exit(1);
    }

    if (cmd.hasOption("h")) {
        formatter.printHelp("RabbitMQProducerMain", options);
        System.exit(2);
    }

    ConnectionFactory factory = new ConnectionFactory();

    if (cmd.hasOption("b")) {
        factory.setHost(cmd.getOptionValue("b"));
    }
    if (cmd.hasOption("u")) {
        factory.setUsername(cmd.getOptionValue("u"));
    }
    if (cmd.hasOption("p")) {
        factory.setPassword(cmd.getOptionValue("p"));
    }
    if (cmd.hasOption("v")) {
        factory.setVirtualHost(cmd.getOptionValue("v"));
    }
    if (cmd.hasOption("n")) {
        factory.setPort(Integer.parseInt(cmd.getOptionValue("n")));
    }

    String exchange = cmd.getOptionValue("e");
    String routingKey = "default.routing.key";
    if (cmd.hasOption("k")) {
        routingKey = cmd.getOptionValue("k");
    }

    boolean durable = cmd.hasOption("d");
    boolean autoDelete = cmd.hasOption("a");
    String type = cmd.getOptionValue("t", "topic");
    boolean single = cmd.hasOption("single");
    int interval = Integer.parseInt(cmd.getOptionValue("interval", "10"));
    int delay = Integer.parseInt(cmd.getOptionValue("delay", "100"));

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    Date stop = sdf.parse(cmd.getOptionValue("stop", sdf.format(new Date())));

    Random r = new Random();
    Calendar timer = Calendar.getInstance();
    timer.setTime(sdf.parse(cmd.getOptionValue("start", "2010-01-01T00:00:00")));

    String msg_template = "{\"utcdt\": \"%s\", \"wp\": %d, \"gender\": \"%s\", \"age\": %d}";

    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.exchangeDeclare(exchange, type, durable, autoDelete, null);

    do {
        int wp = (10 + r.nextInt(90)) * 100;
        String gender = r.nextBoolean() ? "male" : "female";
        int age = 20 + r.nextInt(70);

        String line = String.format(msg_template, sdf.format(timer.getTime()), wp, gender, age);

        channel.basicPublish(exchange, routingKey, null, line.getBytes());

        System.out.println("Sent message: " + line);

        timer.add(Calendar.SECOND, interval);

        Thread.sleep(delay);
    } while ((!single && stop.after(timer.getTime())));

    connection.close();
}