Here you can find the source of convertStringToDate(String dateAsString)
public static Date convertStringToDate(String dateAsString) throws ParseException
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static final SimpleDateFormat dateFormatBulgarian = new SimpleDateFormat("dd.MM.yyyy"); private static final SimpleDateFormat dateFormatWestern = new SimpleDateFormat("yyyy-MM-dd"); public static Date convertStringToDate(String dateAsString) throws ParseException { SimpleDateFormat dateFormat = dateFormatBulgarian; String dateFormatWesternPattern = "\\d{4}-\\d{2}-\\d{2}"; if (dateAsString.matches(dateFormatWesternPattern)) { dateFormat = dateFormatWestern; }/*from w ww.jav a 2 s .c o m*/ Date date = dateFormat.parse(dateAsString); return date; } }