Java tutorial
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date ConvertToDateTime(String format, String dateTimeString) { if (dateTimeString.length() == 0) { return null; } SimpleDateFormat sdf = new SimpleDateFormat(format); Date date; try { date = sdf.parse(dateTimeString); } catch (Exception ex) { date = null; } return date; } }