Here you can find the source of convertToTimestamp(String dateData)
public static Timestamp convertToTimestamp(String dateData) throws Exception
//package com.java2s; import java.sql.Timestamp; import java.util.Calendar; import java.util.GregorianCalendar; public class Main { public static Timestamp convertToTimestamp(String dateData) throws Exception { try {//from w w w . j a v a2 s .co m if (dateData == null) return null; if (dateData.trim().equals("")) return null; int dateObjLength = dateData.length(); String yearString = "2002"; String monthString = "01"; String dayString = "01"; if (dateObjLength >= 4) { yearString = dateData.substring(0, 4); } if (dateObjLength >= 6) { monthString = dateData.substring(4, 6); } if (dateObjLength >= 8) { dayString = dateData.substring(6, 8); } int year = Integer.parseInt(yearString); int month = Integer.parseInt(monthString) - 1; int day = Integer.parseInt(dayString); Calendar cal = new GregorianCalendar(); cal.set(year, month, day); //cal.getTime(); return new Timestamp(cal.getTime().getTime()); } catch (Exception e) { throw new Exception("[DateUtil][convertToTimestamp]" + e.getMessage(), e); } } }