Java tutorial
//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 datetimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static Date parseDatetime(String datetime) throws ParseException { return datetimeFormat.parse(datetime); } public static Date parseDatetime(String datetime, String pattern) throws ParseException { SimpleDateFormat format = (SimpleDateFormat) datetimeFormat.clone(); format.applyPattern(pattern); return format.parse(datetime); } }