Java Date String Format formatDate(String dateString, String delimiter)

Here you can find the source of formatDate(String dateString, String delimiter)

Description

format Date

License

Open Source License

Declaration

public static String formatDate(String dateString, String delimiter) 

Method Source Code

//package com.java2s;
/**//  w  w w  . j a  v  a  2s.  co m
 * Copyright (c) 2015 SK holdings Co., Ltd. All rights reserved.
 * This software is the confidential and proprietary information of SK holdings.
 * You shall not disclose such confidential information and shall use it only in
 * accordance with the terms of the license agreement you entered into with SK holdings.
 * (http://www.eclipse.org/legal/epl-v10.html)
 */

public class Main {

    public static String formatDate(String dateString, String delimiter) {
        if (dateString == null)
            return ""; //$NON-NLS-1$
        String output = dateString.replaceAll("[^0-9]", ""); //$NON-NLS-1$ //$NON-NLS-2$

        if (output.length() == 8) {
            return (output.substring(0, 4) + delimiter + output.substring(4, 6) + delimiter
                    + output.substring(6, 8));
        } else if (output.length() == 6) {
            return (output.substring(0, 4) + delimiter + output.substring(4, 6));
        } else {
            return ""; //$NON-NLS-1$
        }
    }
}

Related

  1. formatDate(String date)
  2. formatDate(String date)
  3. formatDate(String date)
  4. formatDate(String date)
  5. formatDate(String date, int format)
  6. formatDate(String fieldName)
  7. FormatDate(String strDate, char DateSeparator)
  8. formatDate(String unformattedDate, String format)
  9. formatDate(String values)