Java Hour Format formatDate(String date)

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

Description

format Date

License

Open Source License

Declaration

public final static String formatDate(String date) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI_SS = "yyyy-MM-dd HH:mm:ss";

    public final static String formatDate(String date) {
        String str = "";
        if (date == null || date.equals("")) {
            str = "";
        } else if (date.length() >= 10) {
            str = date.substring(0, 10);
        } else {//from www  . j a v  a2 s . co m
            str = date;
        }
        return str;
    }

    /**
     * format date to the style yyyy-MM-dd HH:mm:ss
     *
     * @param date
     * @return
     */
    public final static String formatDate(Date date) {
        return dateTimeToStr(date, DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI_SS);
    }

    public final static String dateTimeToStr(Date date, String format) {
        SimpleDateFormat dateTimeFormat = new SimpleDateFormat(format);
        return dateTimeFormat.format(date);
    }
}

Related

  1. formatDate(final Date date, String pattern)
  2. formatDate(final String date)
  3. formatDate(java.util.Date date, String pattern)
  4. formatDate(java.util.Date dtFormat, String sFormatString)
  5. formatDate(Object obj, String format)
  6. formatDate(String date)
  7. formatDate(String dateTimeString)
  8. formatDate(String format)
  9. formatDate(String inputStr)