Java Date String Format formatDate(String unformattedDate, String format)

Here you can find the source of formatDate(String unformattedDate, String format)

Description

format Date

License

Open Source License

Declaration

public static String formatDate(String unformattedDate, String format) 

Method Source Code

//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
}

Related

  1. formatDate(String date)
  2. formatDate(String date, int format)
  3. formatDate(String dateString, String delimiter)
  4. formatDate(String fieldName)
  5. FormatDate(String strDate, char DateSeparator)
  6. formatDate(String values)
  7. FormatDate6(String strDate)
  8. formatDateLog(String dateStr)
  9. formatDateString(String dateString)