Here you can find the source of convertFormat(String dateData)
public static String convertFormat(String dateData) throws Exception
//package com.java2s; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; public class Main { public static String convertFormat(String dateData) throws Exception { return convertFormat(dateData, "yyyy/MM/dd"); }/*from w w w. j a v a2 s.c o m*/ public static String convertFormat(String dateData, String format) throws Exception { return convertToString(convertToTimestamp(dateData), format); } public static String convertToString(Timestamp dateData) throws Exception { return convertToString(dateData, "yyyy/MM/dd"); } public static String convertToString(Timestamp dateData, String pattern) throws Exception { return convertToString(dateData, pattern, java.util.Locale.CHINA); } public static String convertToString(Timestamp dateData, String pattern, java.util.Locale locale) throws Exception { try { if (dateData == null) { return null; } SimpleDateFormat formatter = new SimpleDateFormat(pattern, locale); //formatter.applyPattern( pattern ); return formatter.format(dateData); } catch (Exception e) { throw new Exception("[DateUtil][convertToString]" + e.getMessage(), e); } } public static Timestamp convertToTimestamp(String dateData) throws Exception { try { 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); } } }