Here you can find the source of StringToDateByFormat(String dateStr, String formatStr)
public static Date StringToDateByFormat(String dateStr, String formatStr)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date StringToDateByFormat(String dateStr, String formatStr) { try {//from w w w. j av a2s . c om SimpleDateFormat sdf = new SimpleDateFormat(formatStr); Date date = sdf.parse(dateStr); return date; } catch (Throwable t) { return null; } } }