Example usage for java.text ParseException printStackTrace

List of usage examples for java.text ParseException printStackTrace

Introduction

In this page you can find the example usage for java.text ParseException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.bitsofproof.example.Simple.java

public static void main(String[] args) {
    Security.addProvider(new BouncyCastleProvider());

    final CommandLineParser parser = new GnuParser();
    final Options gnuOptions = new Options();
    gnuOptions.addOption("h", "help", false, "I can't help you yet");
    gnuOptions.addOption("s", "server", true, "Server URL");
    gnuOptions.addOption("u", "user", true, "User");
    gnuOptions.addOption("p", "password", true, "Password");

    System.out.println("BOP Bitcoin Server Simple Client 3.5.0 (c) 2013-2014 bits of proof zrt.");
    CommandLine cl = null;// www.  j  a v a 2 s.c  om
    String url = null;
    String user = null;
    String password = null;
    try {
        cl = parser.parse(gnuOptions, args);
        url = cl.getOptionValue('s');
        user = cl.getOptionValue('u');
        password = cl.getOptionValue('p');
    } catch (org.apache.commons.cli.ParseException e) {
        e.printStackTrace();
        System.exit(1);
    }
    if (url == null || user == null || password == null) {
        System.err.println("Need -s server -u user -p password");
        System.exit(1);
    }

    BCSAPI api = getServer(url, user, password);
    try {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        long start = System.currentTimeMillis();
        api.ping(start);
        System.out.println("Server round trip " + (System.currentTimeMillis() - start) + "ms");
        api.addAlertListener(new AlertListener() {
            @Override
            public void alert(String s, int severity) {
                System.err.println("ALERT: " + s);
            }
        });
        System.out.println("Talking to " + (api.isProduction() ? "PRODUCTION" : "test") + " server");
        ConfirmationManager confirmationManager = new ConfirmationManager();
        confirmationManager.init(api, 144);
        System.out.printf("Please enter wallet name: ");
        String wallet = input.readLine();
        SimpleFileWallet w = new SimpleFileWallet(wallet + ".wallet");
        TransactionFactory am = null;
        if (!w.exists()) {
            System.out.printf("Enter passphrase: ");
            String passphrase = input.readLine();
            System.out.printf("Enter master (empty for new): ");
            String master = input.readLine();
            if (master.equals("")) {
                w.init(passphrase);
                w.unlock(passphrase);
                System.out.printf("First account: ");
                String account = input.readLine();
                am = w.createAccountManager(account);
                w.lock();
                w.persist();
            } else {
                StringTokenizer tokenizer = new StringTokenizer(master, "@");
                String key = tokenizer.nextToken();
                long since = 0;
                if (tokenizer.hasMoreElements()) {
                    since = Long.parseLong(tokenizer.nextToken()) * 1000;
                }
                w.init(passphrase, ExtendedKey.parse(key), true, since);
                w.unlock(passphrase);
                System.out.printf("First account: ");
                String account = input.readLine();
                am = w.createAccountManager(account);
                w.lock();
                w.persist();
                w.sync(api);
            }
        } else {
            w = SimpleFileWallet.read(wallet + ".wallet");
            w.sync(api);
            List<String> names = w.getAccountNames();
            System.out.println("Accounts:");
            System.out.println("---------");
            String first = null;
            for (String name : names) {
                System.out.println(name);
                if (first == null) {
                    first = name;
                }
            }
            System.out.println("---------");
            am = w.getAccountManager(first);
            System.out.println("Using account " + first);
        }
        confirmationManager.addAccount(am);
        api.registerTransactionListener(am);

        while (true) {
            printMenu();
            String answer = input.readLine();
            System.out.printf("\n");
            if (answer.equals("1")) {
                System.out.printf("The balance is: " + printBit(am.getBalance()) + "\n");
                System.out.printf("     confirmed: " + printBit(am.getConfirmed()) + "\n");
                System.out.printf("    receiveing: " + printBit(am.getReceiving()) + "\n");
                System.out.printf("        change: " + printBit(am.getChange()) + "\n");
                System.out.printf("(      sending: " + printBit(am.getSending()) + ")\n");
            } else if (answer.equals("2")) {
                for (Address a : am.getAddresses()) {
                    System.out.printf(a + "\n");
                }
            } else if (answer.equals("3")) {
                ExtendedKeyAccountManager im = (ExtendedKeyAccountManager) am;
                System.out.printf(
                        im.getMaster().serialize(api.isProduction()) + "@" + im.getCreated() / 1000 + "\n");
            } else if (answer.equals("4")) {
                System.out.printf("Enter passphrase: ");
                String passphrase = input.readLine();
                w.unlock(passphrase);
                ExtendedKeyAccountManager im = (ExtendedKeyAccountManager) am;
                System.out.printf(
                        im.getMaster().serialize(api.isProduction()) + "@" + im.getCreated() / 1000 + "\n");
                w.lock();
            } else if (answer.equals("5")) {
                System.out.printf("Enter passphrase: ");
                String passphrase = input.readLine();
                w.unlock(passphrase);
                System.out.printf("Number of recipients");
                Integer nr = Integer.valueOf(input.readLine());
                Transaction spend;
                if (nr.intValue() == 1) {
                    System.out.printf("Receiver address: ");
                    String address = input.readLine();
                    System.out.printf("amount (Bit): ");
                    long amount = parseBit(input.readLine());
                    spend = am.pay(Address.fromSatoshiStyle(address), amount);
                    System.out.println("About to send " + printBit(amount) + " to " + address);
                } else {
                    List<Address> addresses = new ArrayList<>();
                    List<Long> amounts = new ArrayList<>();
                    long total = 0;
                    for (int i = 0; i < nr; ++i) {
                        System.out.printf("Receiver address: ");
                        String address = input.readLine();
                        addresses.add(Address.fromSatoshiStyle(address));
                        System.out.printf("amount (Bit): ");
                        long amount = parseBit(input.readLine());
                        amounts.add(amount);
                        total += amount;
                    }
                    spend = am.pay(addresses, amounts);
                    System.out.println("About to send " + printBit(total));
                }
                System.out.println("inputs");
                for (TransactionInput in : spend.getInputs()) {
                    System.out.println(in.getSourceHash() + " " + in.getIx());
                }
                System.out.println("outputs");
                for (TransactionOutput out : spend.getOutputs()) {
                    System.out.println(out.getOutputAddress() + " " + printBit(out.getValue()));
                }
                w.lock();
                System.out.printf("Type yes to go: ");
                if (input.readLine().equals("yes")) {
                    api.sendTransaction(spend);
                    System.out.printf("Sent transaction: " + spend.getHash());
                } else {
                    System.out.printf("Nothing happened.");
                }
            } else if (answer.equals("6")) {
                System.out.printf("Address: ");
                Set<Address> match = new HashSet<Address>();
                match.add(Address.fromSatoshiStyle(input.readLine()));
                api.scanTransactionsForAddresses(match, 0, new TransactionListener() {
                    @Override
                    public boolean process(Transaction t) {
                        System.out.printf("Found transaction: " + t.getHash() + "\n");
                        return true;
                    }
                });
            } else if (answer.equals("7")) {
                System.out.printf("Public key: ");
                ExtendedKey ek = ExtendedKey.parse(input.readLine());
                api.scanTransactions(ek, 0, 10, 0, new TransactionListener() {
                    @Override
                    public boolean process(Transaction t) {
                        System.out.printf("Found transaction: " + t.getHash() + "\n");
                        return true;
                    }
                });
            } else if (answer.equals("a")) {
                System.out.printf("Enter account name: ");
                String account = input.readLine();
                am = w.getAccountManager(account);
                api.registerTransactionListener(am);
                confirmationManager.addAccount(am);
            } else if (answer.equals("c")) {
                System.out.printf("Enter account name: ");
                String account = input.readLine();
                System.out.printf("Enter passphrase: ");
                String passphrase = input.readLine();
                w.unlock(passphrase);
                am = w.createAccountManager(account);
                System.out.println("using account: " + account);
                w.lock();
                w.persist();
                api.registerTransactionListener(am);
                confirmationManager.addAccount(am);
            } else if (answer.equals("m")) {
                System.out.printf("Enter passphrase: ");
                String passphrase = input.readLine();
                w.unlock(passphrase);
                System.out.println(w.getMaster().serialize(api.isProduction()));
                System.out.println(w.getMaster().getReadOnly().serialize(true));
                w.lock();
            } else if (answer.equals("s")) {
                System.out.printf("Enter private key: ");
                String key = input.readLine();
                ECKeyPair k = ECKeyPair.parseWIF(key);
                KeyListAccountManager alm = new KeyListAccountManager();
                alm.addKey(k);
                alm.syncHistory(api);
                Address a = am.getNextReceiverAddress();
                Transaction t = alm.pay(a, alm.getBalance(), PaymentOptions.receiverPaysFee);
                System.out.println("About to sweep " + printBit(alm.getBalance()) + " to " + a);
                System.out.println("inputs");
                for (TransactionInput in : t.getInputs()) {
                    System.out.println(in.getSourceHash() + " " + in.getIx());
                }
                System.out.println("outputs");
                for (TransactionOutput out : t.getOutputs()) {
                    System.out.println(out.getOutputAddress() + " " + printBit(out.getValue()));
                }
                System.out.printf("Type yes to go: ");
                if (input.readLine().equals("yes")) {
                    api.sendTransaction(t);
                    System.out.printf("Sent transaction: " + t.getHash());
                } else {
                    System.out.printf("Nothing happened.");
                }
            } else {
                System.exit(0);
            }
        }
    } catch (Exception e) {
        System.err.println("Something went wrong");
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:Pathway2Rdf.java

public static void main(String[] args) {
    // The identifer of the pathway under scrutiny

    // Initiate the model
    Model model = ModelFactory.createDefaultModel();
    try {/*from w  w  w . j  a  va 2s. c o m*/
        File fileName = new File("/tmp/WpGPML/WP1531_45011.gpml");
        String gpml = FileUtils.readFileToString(fileName);
        String wpIdentifier = fileName.getName().substring(0, fileName.getName().indexOf("_"));
        String wpRevision = fileName.getName().substring(fileName.getName().indexOf("_") + 1,
                fileName.getName().indexOf("."));
        addPathway2Rdf(wpIdentifier, wpRevision, gpml);
        System.out.println(FOAF.NS);
        // FileOutputStream fout;
        // fout = new FileOutputStream("/tmp/" + wpIdentifier + ".rdf");
        // model.write(fout, "N-TRIPLE");
    } catch (DOMException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (XPathExpressionException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (ServiceException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (ConverterException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (ParserConfigurationException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (SAXException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.surfs.storage.web.controller.rest.block.BlockService.java

public static void main(String[] args) {
    String a = "Thu Jan 14 3:27 2016";
    SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm yyyy", Locale.US);//MMM dd hh:mm:ss Z yyyy
    SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");//MMM dd hh:mm:ss Z yyyy
    try {//from   w  ww  .ja v  a 2 s . co m
        System.out.println(sdf1.format(sdf.parse(a)));
    } catch (ParseException ex) {
        ex.printStackTrace();
    }
    System.out.println(System.getProperty("user.dir"));
}

From source file:HexFormat.java

public static void main(String[] args) {
    String result;/*from   w  ww . ja  va  2s .c  om*/
    HexFormat format = new HexFormat();

    // byte
    byte bNumber = 0x33;
    result = format.format(bNumber);
    if (result.equals("33")) {
        System.out.print("Success => ");
    } else {
        System.out.print("FAILURE => ");
    }
    System.out.println("Byte: " + bNumber + " (0x" + result + ")");

    bNumber = (byte) 0x85;
    result = format.format(bNumber);
    if (result.equals("85")) {
        System.out.print("Success => ");
    } else {
        System.out.print("FAILURE => ");
    }
    System.out.println("Byte: " + bNumber + " (0x" + result + ")");

    bNumber = (byte) 0x0f;
    result = format.format(bNumber);
    if (result.equals("0f")) {
        System.out.print("Success => ");
    } else {
        System.out.print("FAILURE => ");
    }
    System.out.println("Byte: " + bNumber + " (0x" + result + ")");

    short sNumber = (short) 0xa2b6;
    result = format.format(sNumber);
    if (result.equals("a2b6")) {
        System.out.print("Success => ");
    } else {
        System.out.print("FAILURE => ");
    }
    System.out.println("Byte: " + bNumber + " (0x" + result + ")");

    format.setUpperCase(true);

    int iNumber = (int) 0x4321fedc;
    result = format.format(iNumber);
    if (result.equals("4321FEDC")) {
        System.out.print("Success => ");
    } else {
        System.out.print("FAILURE => ");
    }
    System.out.println("Byte: " + bNumber + " (0x" + result + ")");

    long lNumber = (long) 0x4321fedc4321fedcL;
    result = format.format(lNumber);
    if (result.equals("4321FEDC4321FEDC")) {
        System.out.print("Success => ");
    } else {
        System.out.print("FAILURE => ");
    }
    System.out.println("Byte: " + bNumber + " (0x" + result + ")");

    String num = "0xfe";
    Number number = null;
    Byte bExpect = new Byte((byte) 0xfe);
    try {
        number = format.parse(num);
    } catch (ParseException e) {
        System.out.println(e);
        e.printStackTrace();
    }
    if ((number instanceof Byte) && (number.equals(bExpect))) {
        System.out.print("Success => ");
    } else {
        System.out.print("FAILURE => ");
    }
    System.out.println("Byte: " + bExpect + " result: " + number);

    num = "0xf";
    number = null;
    bExpect = new Byte((byte) 0xf);
    try {
        number = format.parse(num);
    } catch (ParseException e) {
        System.out.println(e);
        e.printStackTrace();
    }
    if ((number instanceof Byte) && (number.equals(bExpect))) {
        System.out.print("Success => ");
    } else {
        System.out.print("FAILURE => ");
    }
    System.out.println("Byte: " + bExpect + " result: " + number);

    num = "0xf0f0";
    number = null;
    Short sExpect = new Short((short) 0xf0f0);
    try {
        number = format.parse(num);
    } catch (ParseException e) {
        System.out.println(e);
        e.printStackTrace();
    }
    if ((number instanceof Short) && (number.equals(sExpect))) {
        System.out.print("Success => ");
    } else {
        System.out.print("FAILURE => ");
    }
    System.out.println("Short: " + sExpect + " result: " + number);

    num = "0xdEAdbEEf";
    number = null;
    Integer iExpect = new Integer((int) 0xdEAdbEEf);
    try {
        number = format.parse(num);
    } catch (ParseException e) {
        System.out.println(e);
        e.printStackTrace();
    }
    if ((number instanceof Integer) && (number.equals(iExpect))) {
        System.out.print("Success => ");
    } else {
        System.out.print("FAILURE => ");
    }
    System.out.println("Integer: " + iExpect + " result: " + number);
}

From source file:com.radvision.icm.service.vcm.ICMService.java

public static void main(String[] args) {
    long currTime = System.currentTimeMillis();
    //      long tmpTime = currTime - 24 * 60 * 60 * 1000;
    Date dt = new Date(currTime);
    //      Calendar cal = Calendar.getInstance();
    //      cal.setTime(dt);
    //      System.out.println(cal);

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    String s = df.format(dt);//from w w w . j av  a2  s . c  om
    System.out.println(s);
    try {
        Date dtNew = df.parse(s);
        long newTime = dtNew.getTime();
        long minutes = (currTime - newTime) / (1000 * 60);
        System.out.println(minutes / 60 + ":" + minutes % 60);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.icebreak.p2p.trade.impl.InvestServiceImpl.java

public static void main(String[] args) {
    int days = 56;
    Calendar endTime = Calendar.getInstance();
    Calendar beginTime = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = null;//w  w w.  j  a  v a2 s . co m
    try {
        date = sdf.parse("2015-01-27 09:49:21");
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    beginTime.setTime(date);
    int cutDays = (int) ((endTime.getTimeInMillis() - beginTime.getTimeInMillis()) / 1000 / 60 / 60 / 24);
    days = days - cutDays;
    days = (days < 0 ? 0 : days);
    System.out.println("cutDays: " + cutDays);
    System.out.println("days: " + days);
}

From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java

public static void main(String[] args) {
    ICalTimeZone tzUTC = ICalTimeZone.getUTC();
    TimeZoneMap tzmap = new TimeZoneMap(tzUTC);
    ParsedDateTime dtStart = null;// w w w .j ava2  s . c  o m
    try {
        dtStart = ParsedDateTime.parse("20050101T123456", tzmap, tzUTC, tzUTC);
    } catch (ParseException e) {
        System.out.println("Caught ParseException at start: " + e);
    }

    Date rangeStart;
    Date rangeEnd;

    GregorianCalendar cal = new GregorianCalendar();
    cal.clear();
    cal.setTimeZone(tzUTC);

    cal.set(2005, 4, 15, 0, 0, 0);
    rangeStart = cal.getTime();

    cal.set(2006, 0, 1, 0, 0, 0);
    rangeEnd = cal.getTime();

    try {
        ZRecur test = new ZRecur("FREQ=DAILY;BYMONTH=5,6", tzmap);
        System.out.println("\n\n" + test.toString() + "\n-------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            cal.setTimeZone(tzUTC);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=DAILY;BYMONTH=5,6;BYDAY=TH,-1MO", tzmap);
        System.out.println("\n\n" + test.toString() + "\n-------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            cal.setTimeZone(tzUTC);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=DAILY;BYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31", tzmap);
        System.out.println("\n\n" + test.toString() + "\n-------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=DAILY;BYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31;BYDAY=SU,SA", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=DAILY;BYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31;BYDAY=SU,SA;BYHOUR=21,0",
                tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur(
                "FREQ=DAILY;BYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31;BYDAY=SU;BYHOUR=21,0;BYMINUTE=23", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur(
                "FREQ=DAILY;BYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31;BYDAY=SU;BYHOUR=1,21,0;BYSECOND=0,59", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        // parse error testing
        ZRecur test = new ZRecur(
                "FREQ=DAILY;BIYMONTH=5,6;BYMONTHDAY=1,3,5,7,9,31;BYDAY=SU;BYHOUR=1,21,0;BYSECOND=0,59;BYSETPOS=1,-1,3,1000,,-1000",
                tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=HOURLY;BIYMONTH=6;BYMONTHDAY=1,3;BYHOUR=2,14", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=HOURLY;BIYMONTH=6;BYMONTHDAY=1;;BYMINUTE=10;BYSECOND=11,12", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    cal.set(2010, 0, 1, 0, 0, 0);
    rangeEnd = cal.getTime();

    try {
        ZRecur test = new ZRecur("FREQ=YEARLY", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=YEARLY;BYYEARDAY=-1", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ZRecur test = new ZRecur("FREQ=SECONDLY", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    try {
        ParsedDateTime myDtStart = ParsedDateTime.parse("16010101T020000", tzmap, tzUTC, tzUTC);
        ZRecur test = new ZRecur("FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=12;BYDAY=-1SU", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(myDtStart, rangeStart.getTime(),
                rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ParseException e) {
        System.out.println("Caught ParseException" + e);
        e.printStackTrace();
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

    cal.set(2010, 0, 1, 0, 0, 0);
    rangeEnd = cal.getTime();

    try {
        ZRecur test = new ZRecur("FREQ=YEARLY;BYMONTH=12;BYDAY=1WE", tzmap);
        System.out.println(
                "\n\n" + test.toString() + "\n--------------------------------------------------------------");
        List<Date> dateList = test.expandRecurrenceOverRange(dtStart, rangeStart.getTime(), rangeEnd.getTime());
        for (Date d : dateList) {
            cal.setTime(d);
            System.out.printf("%tc\n", cal);
        }
    } catch (ServiceException e) {
        System.out.println("Caught ServiceException" + e);
        e.printStackTrace();
    }

}

From source file:Main.java

public static boolean isValidFormat(String format, String value) {
    Date date = null;// www  . j  av  a 2  s.co  m
    try {
        date = new SimpleDateFormat(format).parse(value);
    } catch (ParseException ex) {
        ex.printStackTrace();
    }
    return date != null;
}

From source file:Main.java

public static Date convertStringToDate(String dateIn) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    Date date = null;//w  w  w.  j  a  v a 2 s  .  co m
    try {
        date = formatter.parse(dateIn);
        System.out.println(date);
        System.out.println(formatter.format(date));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date;
}

From source file:Main.java

public static long stringToTime(String dateString, SimpleDateFormat dateFormat) {
    try {/* ww  w .  j  a  v  a 2  s.c om*/
        return dateFormat.parse(dateString).getTime();
    } catch (ParseException e) {
        e.printStackTrace();
        return 0;
    }
}