Here you can find the source of stringToDate(final String dateString)
public static Date stringToDate(final String dateString)
//package com.java2s; /**/*from w w w . j a v a 2 s .c o m*/ * * Licensed under the GNU General Public License (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.gnu.org/licenses/gpl.txt * * 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. * * * @author Vadim Kisen * * copyright 2010 by uTest */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static String[] formats = { "yyyy-MM-dd'T'HH:mm:ssz", // "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd", "MM/dd/yyyy", "MM/dd/yyyy h:mm a" }; public static Date stringToDate(final String dateString) { Date ret = null; for (final String format : formats) { try { final SimpleDateFormat frm = new SimpleDateFormat(format); ret = frm.parse(dateString); break; } catch (final ParseException e) { continue; } } return ret; } }