Java Parse Date Pattern YYYY parseToDateLenient(final String date, final String format, final boolean lenient)

Here you can find the source of parseToDateLenient(final String date, final String format, final boolean lenient)

Description

Parses the String date to a date object.

License

Apache License

Parameter

Parameter Description
date The Date as String
format The Format for the Date to parse
lenient Specify whether or not date/time interpretation is to be lenient.

Return

The formated Date or null.

Declaration

public static Date parseToDateLenient(final String date, final String format, final boolean lenient) 

Method Source Code

//package com.java2s;
/**//from  w w w . j  a  v a2  s.  com
 * Copyright (C) 2007 Asterios Raptis
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    /**
     * Parses the String date to a date object. For example: USA-Format is : yyyy-MM-dd
     *
     * @param date
     *            The Date as String
     * @param format
     *            The Format for the Date to parse
     * @param lenient
     *            Specify whether or not date/time interpretation is to be lenient.
     * @return The formated Date or null.
     */
    public static Date parseToDateLenient(final String date, final String format, final boolean lenient) {
        if (date == null || format == null || format.length() <= 0) {
            return null;
        }
        final DateFormat df = new SimpleDateFormat(format);
        df.setLenient(lenient);
        Date parsedDate = null;
        try {
            parsedDate = df.parse(date);
        } catch (final ParseException e) {
            // ignore...
        }
        return parsedDate;
    }
}

Related

  1. parseStringToUtilDate(String strDate)
  2. parseTIPPDate(String dateString)
  3. parseToDate(final String date, final String format)
  4. parseToDate(String date)
  5. parseToDate(String date, String format)
  6. parseToGregorianCalendar(String dateString)
  7. parseToRegExcel(String raw)
  8. parseToString(Date date)
  9. parseToString(Date date, String format)