Java tutorial
//package com.java2s; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static String stringDateToString(String format, String toFormat, String dateString) { ParsePosition position = new ParsePosition(0); SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.getDefault()); SimpleDateFormat StringDateFormat = new SimpleDateFormat(toFormat); Date dateValue = null; String data = ""; try { dateValue = simpleDateFormat.parse(dateString, position); data = StringDateFormat.format(dateValue); } catch (Exception e) { e.printStackTrace(); } return data; } public static String stringDateToString(String format, String dateString) { ParsePosition position = new ParsePosition(0); SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.getDefault()); SimpleDateFormat StringDateFormat = new SimpleDateFormat(format); Date dateValue = null; String data = ""; try { dateValue = simpleDateFormat.parse(dateString, position); data = StringDateFormat.format(dateValue); } catch (Exception e) { e.printStackTrace(); } return data; } }