Here you can find the source of convertDateTimeStrFormat(String dateStr, String pattern, String newPattern)
public static String convertDateTimeStrFormat(String dateStr, String pattern, String newPattern) throws ParseException
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; public class Main{ public static String DEFAULTFORMAT = "yyyy-MM-dd HH:mm:ss"; public static String convertDateTimeStrFormat(String dateStr, String pattern, String newPattern) throws ParseException { return DateTimeUtil.formatCalendar( DateTimeUtil.parseString(dateStr, pattern), newPattern); }//from ww w . j a va 2 s . c om public static String formatCalendar(Calendar calendar) { return formatCalendar(calendar, DEFAULTFORMAT); } public static String formatCalendar(Calendar calendar, String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); // sdf.setTimeZone(TimeZone.getTimeZone(timeZone)); return sdf.format(calendar.getTime()); } public static Calendar parseString(String dateStr, String pattern) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(pattern); Date date = sdf.parse(dateStr); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar; } public static Calendar parseString(String dateStr) throws ParseException { return parseString(dateStr, DEFAULTFORMAT); } }