Java Date String Format formatDateString(String dateString)

Here you can find the source of formatDateString(String dateString)

Description

Change date format from MM/dd/YYYY to yyyy/MM/dd

License

Apache License

Parameter

Parameter Description
dateString a parameter

Declaration

public static String formatDateString(String dateString) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static final String DEFAULT_DELIMETER = "-";

    /**//  w w  w.j a v  a  2 s.c  om
     * Change date format from MM/dd/YYYY to yyyy/MM/dd
     * @param dateString
     * @return
     */
    public static String formatDateString(String dateString) {
        // bulan-tanggal-tahun
        String arrStr[] = dateString.split(DEFAULT_DELIMETER);

        if (arrStr[1].length() == 1)
            arrStr[1] = String.format("0%s", arrStr[1]);

        if (arrStr[0].length() == 1)
            arrStr[0] = String.format("0%s", arrStr[0]);

        // tahun-bulan-tanggal
        return String.format("%s-%s-%s", arrStr[2], arrStr[0], arrStr[1]);
    }
}

Related

  1. formatDate(String unformattedDate, String format)
  2. formatDate(String values)
  3. FormatDate6(String strDate)
  4. formatDateLog(String dateStr)
  5. FormatDateString(String dateString)
  6. formatDateToParse(String date, String errorMessage)
  7. formatDay(String date)
  8. formate8Date(String str)
  9. formatIso8601ToSimpleDate(String iso8601)