Java Date String Format dateFormatFix(String str)

Here you can find the source of dateFormatFix(String str)

Description

date Format Fix

License

Open Source License

Declaration

public static String dateFormatFix(String str) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) Emil Crumhorn - Hexapixel.com - emil.crumhorn@gmail.com
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*w ww  .ja va 2  s  .  c  o  m*/
 *    emil.crumhorn@gmail.com - initial API and implementation
 *******************************************************************************/

public class Main {
    public static String dateFormatFix(String str) {
        if (str.indexOf("M") != -1 && str.indexOf("MM") == -1 && str.indexOf("MMM") == -1) {
            str = str.replaceAll("M", "MM");
        }
        if (str.indexOf("d") != -1 && str.indexOf("dd") == -1 && str.indexOf("ddd") == -1) {
            str = str.replaceAll("d", "dd");
        }
        if (str.indexOf("y") != -1 && str.indexOf("yy") == -1 && str.indexOf("yyy") == -1) {
            str = str.replaceAll("y", "yy");
        }

        return str;

    }
}

Related

  1. dateFormat(String date)
  2. dateFormat(String datetime)
  3. dateFormat(String strYear, String strMonth, String strDay)
  4. formatDate(byte[] btValue, int iOffset, int iLength)
  5. formatDate(int year, int month, int day)
  6. formatDate(Integer date)
  7. formatDate(Integer day, Integer month, Integer year)