Here you can find the source of parseSqlDate(final String value)
static java.sql.Date parseSqlDate(final String value)
//package com.java2s; /*/*from ww w. j ava 2 s .com*/ * Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved. * * 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.ParseException; public class Main { static final String SQL_DATE_FORMAT = "yyyy-MM-dd"; static java.sql.Date parseSqlDate(final String value) { try { // JDK format in Date.valueOf is compatible with DATE_FORMAT return java.sql.Date.valueOf(value); } catch (IllegalArgumentException e) { return throwRuntimeParseException(value, new ParseException(value, 0), SQL_DATE_FORMAT); } } private static <T> T throwRuntimeParseException(String value, Exception e, String... legalFormats) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < legalFormats.length; i++) { sb.append("'").append(legalFormats[i]).append("'"); if (i < legalFormats.length - 2) { sb.append(", "); } } throw new RuntimeException( "Unable to parse date from value: '" + value + "' ! Valid format are: " + sb.toString() + ".", e); } }