Here you can find the source of formatDate(String unformattedDate, String format)
public static String formatDate(String unformattedDate, String format)
//package com.java2s; //License from project: Open Source License public class Main { public static String formatDate(String unformattedDate, String format) { // Format: year-month-day-hours-minutes-seconds String[] splitUFDate = unformattedDate.split("-"); if (splitUFDate.length != 6) return ""; String formattedDate = format; String[] patterns = { "Y", "M", "D", "h", "m", "s" }; int l = Math.min(patterns.length, splitUFDate.length); for (int i = 0; i < l; ++i) formattedDate = formattedDate.replaceAll(patterns[i], splitUFDate[i]); return formattedDate; }//w ww. j a v a 2 s. com }