Tuesday, 17 June 2014

Validate a timestamp is ISO time format

public Boolean isISOTimestamp(String input) throws IOException {

        try {

            if (input == null || input.length() == 0) return false;

            DateTimeFormatter parser = ISODateTimeFormat.dateTimeNoMillis();
            parser.parseDateTime(input);

        } catch (IllegalArgumentException iae) {
            return false;
        } catch (ClassCastException e) {

            return false;
        }

        return true;
    }

No comments:

Post a Comment