Here you can find the source of getDateFromString(String dateString, String format)
public static Date getDateFromString(String dateString, String format) throws ParseException
//package com.java2s; /**// www .java 2s .c om * License: https://github.com/votingsystem/votingsystem/wiki/Licencia */ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; public class Main { private static final DateFormat isoDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault()); public static Date getDateFromString(String dateString) throws ParseException { if (dateString.endsWith("Z")) return isoDateFormat.parse(dateString); else { DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); return formatter.parse(dateString); } } public static Date getDateFromString(String dateString, Locale locale) throws ParseException { DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", locale); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); return formatter.parse(dateString); } public static Date getDateFromString(String dateString, String format) throws ParseException { DateFormat formatter = new SimpleDateFormat(format); return formatter.parse(dateString); } }