Example usage for java.text SimpleDateFormat setLenient

List of usage examples for java.text SimpleDateFormat setLenient

Introduction

In this page you can find the example usage for java.text SimpleDateFormat 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:com.enonic.cms.domain.user.field.UserFieldHelper.java

private static SimpleDateFormat[] getSupportedDateFormats() {
    SimpleDateFormat iso = new SimpleDateFormat("yyyy-MM-dd");
    iso.setLenient(false);

    SimpleDateFormat old = new SimpleDateFormat("dd.MM.yyyy");
    old.setLenient(false);/*w  ww. j  a v a2 s . co m*/

    SimpleDateFormat standard = DATE_FORMAT;
    standard.setLenient(false);

    return new SimpleDateFormat[] { iso, old, standard };
}

From source file:org.apache.syncope.core.misc.DataFormat.java

public static String format(final Date date, final boolean lenient, final String conversionPattern) {
    SimpleDateFormat sdf = DATE_FORMAT.get();
    if (conversionPattern != null) {
        sdf.applyPattern(conversionPattern);
    }/*from   ww  w  .ja  va 2s  .com*/
    sdf.setLenient(lenient);
    return sdf.format(date);
}

From source file:Main.java

public static String formatDate(String date) {
    String returnDate = date;//from w ww.j ava  2 s  .  c  o m
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", java.util.Locale.ENGLISH);
    SimpleDateFormat expectedFormat = new SimpleDateFormat("EE,  MMM dd hh:mm a", java.util.Locale.ENGLISH);

    dateFormat.setLenient(true);
    try {
        returnDate = expectedFormat.format(dateFormat.parse(date));

    } catch (ParseException e) {
    }
    if (returnDate == null || returnDate.length() == 0) {
        dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", java.util.Locale.ENGLISH);

        dateFormat.setLenient(true);
        try {
            returnDate = expectedFormat.format(dateFormat.parse(date));

        } catch (ParseException e) {
        }
    }
    return returnDate;
}

From source file:jp.co.opentone.bsol.framework.core.util.DateUtil.java

/**
 * ???(?????????null).//from   w  ww.java 2 s.c o  m
 * @param format ?
 * @param date 
 * @return ??
 */
public static Date convertStringToDate(String format, String date) {
    if (StringUtils.isEmpty(date)) {
        return null;
    }
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    sdf.setLenient(false);

    ParsePosition pos = new ParsePosition(0);
    Date d = sdf.parse(date, pos);
    //  ????????????
    //  ???????????
    if (pos.getIndex() != date.length()) {
        return null;
    }
    return d;
}

From source file:vng.paygate.domain.common.DateUtils.java

public static boolean checkDateFormat(String inDate, String format) {
    if (inDate == null) {
        return false;
    }//from   w  ww  .  j a va 2 s. c  o  m
    SimpleDateFormat dateFormat = new SimpleDateFormat(format);
    if (inDate.trim().length() != dateFormat.toPattern().length()) {
        return false;
    }
    dateFormat.setLenient(false);
    try {
        dateFormat.parse(inDate.trim());
    } catch (Exception ex) {
        return false;
    }
    return true;
}

From source file:codepath.watsiapp.utils.Util.java

public static String getFormatedDate(Date date) {

    SimpleDateFormat sf = new SimpleDateFormat(DATE_FORMAT);
    sf.setLenient(true);
    return sf.format(date);

}

From source file:org.ibankapp.base.validation.IdentifierValidation.java

public static boolean isIdCardNo(String cardNo) {

    cardNo = cardNo.trim().toUpperCase();

    if (cardNo.length() != 18) {
        return false;
    }/*  w ww. j av  a2  s.c  o  m*/

    if (!StringUtils.isNumeric(cardNo.substring(0, 17))) {
        return false;
    }

    if (!Character.isDigit(cardNo.charAt(17)) && cardNo.charAt(17) != 'X') {
        return false;
    }

    Set<String> zones = new HashSet<>();

    Collections.addAll(zones, "11", "12", "13", "14", "15", "21", "22", "23", "31", "32", "33", "34", "35",
            "36", "37", "41", "42", "43", "44", "45", "46", "50", "51", "52", "53", "54", "61", "62", "63",
            "64", "71", "81", "82", "91");

    if (!zones.contains(cardNo.substring(0, 2))) {
        return false;
    }

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    sdf.setLenient(false);

    try {
        Date birthday = sdf.parse(cardNo.substring(6, 14));
        if (birthday.after(new Date())) {
            return false;
        }
    } catch (ParseException e) {
        return false;
    }

    return cardNo.charAt(17) == getIdCardNoCheckBit(cardNo.substring(0, 17));

}

From source file:com.nridge.core.base.std.DatUtl.java

/**
 * Attempts to detect the date/time format of the value and create
 * a 'Date' object.//from   www  .  j  a v a2  s .  c  o  m
 *
 * @param aDateTimeValue String value.
 * @return Date object if the format is recognized or <i>null</i>.
 */
public static Date detectCreateDate(String aDateTimeValue) {
    Date createDate = null;

    if (StringUtils.isNotEmpty(aDateTimeValue)) {
        if (mDateFormatList == null) {
            mDateFormatList = new ArrayList<SimpleDateFormat>();
            mDateFormatList.add(new SimpleDateFormat(Field.FORMAT_ISO8601DATETIME_DEFAULT));
            mDateFormatList.add(new SimpleDateFormat(Field.FORMAT_ISO8601DATETIME_MILLI2D));
            mDateFormatList.add(new SimpleDateFormat(Field.FORMAT_ISO8601DATETIME_MILLI3D));
            mDateFormatList.add(new SimpleDateFormat(Field.FORMAT_RFC1123_DATE_TIME));
            mDateFormatList.add(new SimpleDateFormat(Field.FORMAT_SQLORACLEDATE_DEFAULT));
            mDateFormatList.add(new SimpleDateFormat(Field.FORMAT_SQLISODATE_DEFAULT));
            mDateFormatList.add(new SimpleDateFormat(Field.FORMAT_SQLISOTIME_DEFAULT));
            mDateFormatList.add(new SimpleDateFormat(Field.FORMAT_SQLISODATETIME_DEFAULT));
            mDateFormatList.add(new SimpleDateFormat(Field.FORMAT_DATE_DEFAULT));
            mDateFormatList.add(new SimpleDateFormat(Field.FORMAT_TIME_AMPM));
            mDateFormatList.add(new SimpleDateFormat(Field.FORMAT_TIME_PLAIN));
            mDateFormatList.add(new SimpleDateFormat(Field.FORMAT_TIMESTAMP_PACKED));
        }

        ParsePosition parsePosition = new ParsePosition(0);
        for (SimpleDateFormat sdf : mDateFormatList) {
            sdf.setLenient(false);
            createDate = sdf.parse(aDateTimeValue, parsePosition);
            if (createDate != null)
                break;
        }
    }
    return createDate;
}

From source file:jp.go.nict.langrid.management.web.utility.DateUtil.java

/**
 * /*from w  w  w. j a v  a2 s  .  co  m*/
 * 
 */
public static Date getDate(String text) throws ParseException {
    ParsePosition pp = new ParsePosition(0);
    if (text == null) {
        throw new ParseException("", pp.getIndex());
    }
    int textLength = text.length();
    for (SimpleDateFormat format : formats) {
        format.setLenient(false);
        pp = new ParsePosition(0);
        Date ret = format.parse(text, pp);
        if (textLength == pp.getIndex()) {
            return ret;
        }
    }
    throw new ParseException("", pp.getIndex());
}

From source file:org.akaza.openclinica.core.form.StringUtil.java

/**
 * Return true if a date String is the same day when it is parsed by two
 * different dateFormats. The year can only between 1000 and 9999.
 * SimpleDataFormat uses the default locale.
 *
 * @param dateFormat1/*  ww  w .j ava2s.c om*/
 * @param dateFormat2
 * @param dateStr
 * @return
 */
public static boolean isSameDate(String dateFormat1, String dateFormat2, String dateStr) {
    SimpleDateFormat sdf1 = new SimpleDateFormat(dateFormat1);
    sdf1.setLenient(false);
    SimpleDateFormat sdf2 = new SimpleDateFormat(dateFormat2);
    sdf2.setLenient(false);
    return sameDate(sdf1, sdf2, dateStr);
}