Java Date String Format dateFormat(String date)

Here you can find the source of dateFormat(String date)

Description

date Format

License

Open Source License

Declaration

public static String dateFormat(String date) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static String dateFormat(String date) {
        if (date.length() == 10) {
            return date.substring(0, 2) + "-" + date.substring(2, 4) + ' ' + date.substring(4, 6) + ':'
                    + date.substring(6, 8) + ':' + date.substring(8, 10);
        } else if (date.length() == 8) {
            return date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6, 8);
        } else if (date.length() == 6) {
            return date.substring(0, 2) + ":" + date.substring(2, 4) + ":" + date.substring(4, 6);
        } else if (date.length() == 4) {
            return date.substring(0, 2) + ":" + date.substring(2, 4);
        } else if (date.length() == 14) {
            return date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6, 8) + ' '
                    + date.substring(8, 10) + ":" + date.substring(10, 12) + ":" + date.substring(12, 14);
            /*/*from  ww  w  . j  av  a  2 s  .c om*/
             * try { date =
             * showDateFormatZHCN.format(sysDateFormat.parse(date)); } catch
             * (ParseException e) { e.printStackTrace(); } return date;
             */
        } else {
            return date;
        }
    }
}

Related

  1. dateFormat(String datetime)
  2. dateFormat(String strYear, String strMonth, String strDay)
  3. dateFormatFix(String str)
  4. formatDate(byte[] btValue, int iOffset, int iLength)