Here you can find the source of StrToDateTimeFormat(String timestampStr,String pattern)
public static String StrToDateTimeFormat(String timestampStr,String pattern) throws ParseException
//package com.java2s; //License from project: Apache License import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.text.ParseException; public class Main { public static String StrToDateTimeFormat(String timestampStr, String pattern) throws ParseException { String s = ""; try {/*from www. j a v a 2s .com*/ s = String.valueOf(StrToTimestamp(timestampStr, pattern)); s = s.substring(0, pattern.length()); } catch (Exception e) { } return s; } public static Timestamp StrToTimestamp(String timestampStr, String pattern) throws ParseException { java.util.Date date = null; SimpleDateFormat format = new SimpleDateFormat(pattern); try { date = format.parse(timestampStr); } catch (ParseException ex) { throw ex; } return date == null ? null : new Timestamp(date.getTime()); } }