Here you can find the source of parseToDateLenient(final String date, final String format, final boolean lenient)
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. |
public static Date parseToDateLenient(final String date, final String format, final boolean lenient)
//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; } }