Example usage for java.text DateFormat setLenient

List of usage examples for java.text DateFormat setLenient

Introduction

In this page you can find the example usage for java.text DateFormat setLenient.

Prototype

public void setLenient(boolean lenient) 

Source Link

Document

Specify whether or not date/time parsing is to be lenient.

Usage

From source file:DateTest.java

public static void main(String[] args) throws ParseException {
    DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT);
    formatter.setLenient(false);
    Date theDate = formatter.parse(args[0]);
    System.out.println(theDate);//from   w  ww.ja va 2 s.c om
}

From source file:Main.java

public static boolean isValidDateStr(String date) throws Exception {

    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
    df.setLenient(false);
    df.parse(date);/*from   w w w  . jav  a2  s  .c o  m*/

    return true;
}

From source file:Main.java

public static boolean isDateValid(int day, int month, int year) {
    try {/*w w  w  .  j  ava  2  s. c o  m*/
        DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        df.setLenient(false);
        df.parse(day + "-" + month + "-" + year);
        return true;
    } catch (ParseException e) {
        return false;
    }
}

From source file:Main.java

public static int[] parseDate(String dateString) {
    try {//ww w .  jav  a 2s  .  com
        DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
        formatter.setLenient(false);
        Date date = (Date) formatter.parse(dateString);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int[] dateInts = new int[3];
        dateInts[0] = cal.get(Calendar.DAY_OF_MONTH);
        dateInts[1] = cal.get(Calendar.MONTH);
        dateInts[2] = cal.get(Calendar.YEAR);

        return dateInts;
    } catch (Exception e) {
        throw new RuntimeException(
                "Could not parse date:'" + dateString + "'. Date format is dd-MM-yyyy (ex: 31-12-2011).", e);
    }
}

From source file:com.dhenton9000.selenium.generic.UtilMethods.java

public static String getPreviousDate(int daysAgo) {
    DateFormat newFormat = new SimpleDateFormat("MM/dd/yyyy");
    newFormat.setLenient(true);
    Calendar cal = Calendar.getInstance();
    cal.setTime(new java.util.Date());
    cal.add(Calendar.DATE, -1 * daysAgo);
    return newFormat.format(cal.getTime());
}

From source file:edu.sampleu.bookstore.document.attribs.XPathSearchableAttribute.java

/**
 * Creates an DocumentAttribute of the specified type
 */// w ww .j  a  v  a  2  s  .c  om
protected static DocumentAttribute createAttribute(String name, String value, String dataTypeValue)
        throws ParseException {
    if (StringUtils.isBlank(dataTypeValue)) {
        return DocumentAttributeFactory.createStringAttribute(name, value);
    } else if (KewApiConstants.SearchableAttributeConstants.DATA_TYPE_STRING.equals(dataTypeValue)) {
        return DocumentAttributeFactory.createStringAttribute(name, value);
    } else if (KewApiConstants.SearchableAttributeConstants.DATA_TYPE_DATE.equals(dataTypeValue)) {
        try {
            return DocumentAttributeFactory.createDateTimeAttribute(name,
                    CoreApiServiceLocator.getDateTimeService().convertToDate(value));
        } catch (ParseException pe) {
            // HACK: KRAD is sending us yyyy-MM-dd which is not in the standard format list...
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            dateFormat.setLenient(false);
            Date date = dateFormat.parse(value);
            return DocumentAttributeFactory.createDateTimeAttribute(name, date);
        }
    } else if (KewApiConstants.SearchableAttributeConstants.DATA_TYPE_LONG.equals(dataTypeValue)) {
        return DocumentAttributeFactory.createIntegerAttribute(name, new BigInteger(value));
    } else if (KewApiConstants.SearchableAttributeConstants.DATA_TYPE_FLOAT.equals(dataTypeValue)) {
        return DocumentAttributeFactory.createDecimalAttribute(name, new BigDecimal(value));
    }
    throw new IllegalArgumentException("Invalid dataTypeValue was given: " + dataTypeValue);
}

From source file:org.talend.dataprofiler.core.ui.utils.CheckValueUtils.java

/**
 * DOC zqin Comment method "isDateValue".
 * /*from w  w  w  .j  a va  2s  .co m*/
 * @param inputString
 * @return
 */
public static boolean isDateValue(String inputString) {

    if (!isEmpty(inputString)) {
        try {
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$
            df.setLenient(false);
            df.parse(inputString);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    return false;
}

From source file:de.knurt.fam.template.util.ContactDetailsRequestHandler.java

/**
 * return the date from a date input. input must have format ddMMyyyy (or
 * dd.MM.yyyy etc.).//ww  w . j  ava2 s  . c  om
 * 
 * @param birthdate
 *            as put in
 * @return the date from a date input
 */
public static Date getDate(String birthdate) {
    Date result = null;
    if (birthdate != null) {
        String input = birthdate.trim().replaceAll("[^0-9]", "");
        try {
            DateFormat df = new SimpleDateFormat("ddMMyyyy");
            df.setLenient(false);
            result = df.parse(input);
        } catch (ParseException ex) {
        }
    }
    return result;

}

From source file:org.apache.falcon.util.DateUtil.java

private static DateFormat getISO8601DateFormat(TimeZone tz, String mask) {
    DateFormat dateFormat = new SimpleDateFormat(mask);
    // Stricter parsing to prevent dates such as 2011-12-50T01:00Z (December 50th) from matching
    dateFormat.setLenient(false);
    dateFormat.setTimeZone(tz);/*from   www. j av a2  s  .c o  m*/
    return dateFormat;
}

From source file:eu.finesce.emarketplace.core.Scilab2Orion.java

private static List<Predictions> loadDataForPredictions() {

    List<Predictions> list = new ArrayList<Predictions>();
    ;//from w w  w  .j av a2s .  c o  m

    try {
        InputStream is = new FileInputStream(fileInputPredictions);
        DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
        sdf.setLenient(false);
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));

        String line = reader.readLine();// header
        line = reader.readLine();
        //list = new ArrayList<Predictions>();
        while (line != null) {
            Iterator<String> iterator = Arrays.asList(line.split(";")).iterator();

            Predictions predictions = new Predictions();

            //String dataStr = iterator.next();

            predictions.setLoadPredictionsTime(parseLong(iterator.next()));

            //            try {
            //               Date loadTimePrediction = sdf.parse(dataStr);
            //               predictions.setLoadPredictionsTime(loadTimePrediction
            //                     .getTime() / 1000);
            //            } catch (ParseException e) {
            //               predictions.setLoadPredictionsTime(0);
            //               LOGGER.error("Error parsing loadTimePrediction by input file, the date is set to zero value");
            //            }
            //
            predictions.setMeterId(iterator.next());
            predictions.setIdUser(iterator.next());

            predictions.setCurrentTime(new Date().getTime() / 1000);

            predictions.setAfter1hUpstreamActivePower(parseDouble(iterator.next()));
            predictions.setAfter1hUpstreamReactivePower(parseDouble(iterator.next()));
            predictions.setAfter1hDownstreamActivePower(parseDouble(iterator.next()));
            predictions.setAfter1hDownstreamReactivePower(parseDouble(iterator.next()));

            predictions.setAfter3hUpstreamActivePower(parseDouble(iterator.next()));
            predictions.setAfter3hUpstreamReactivePower(parseDouble(iterator.next()));
            predictions.setAfter3hDownstreamActivePower(parseDouble(iterator.next()));
            predictions.setAfter3hDownstreamReactivePower(parseDouble(iterator.next()));

            predictions.setAfter6hUpstreamActivePower(parseDouble(iterator.next()));
            predictions.setAfter6hUpstreamReactivePower(parseDouble(iterator.next()));
            predictions.setAfter6hDownstreamActivePower(parseDouble(iterator.next()));
            predictions.setAfter6hDownstreamReactivePower(parseDouble(iterator.next()));

            predictions.setAfter12hUpstreamActivePower(parseDouble(iterator.next()));
            predictions.setAfter12hUpstreamReactivePower(parseDouble(iterator.next()));
            predictions.setAfter12hDownstreamActivePower(parseDouble(iterator.next()));
            predictions.setAfter12hDownstreamReactivePower(parseDouble(iterator.next()));

            predictions.setAfter24hUpstreamActivePower(parseDouble(iterator.next()));
            predictions.setAfter24hUpstreamReactivePower(parseDouble(iterator.next()));
            predictions.setAfter24hDownstreamActivePower(parseDouble(iterator.next()));
            predictions.setAfter24hDownstreamReactivePower(parseDouble(iterator.next()));

            list.add(predictions);
            line = reader.readLine();
        }
        reader.close();
    } catch (IOException e) {
        LOGGER.error("Error IO in loadDataForPredictions ", e);
    } catch (Exception e) {
        LOGGER.error("Error in loadDataForPredictions ", e);
    }
    return list;
}