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 static Date formatDate(String date) 

Method Source Code


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

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static String formatDate(Date date) {
        return format(date, "yyyy-MM-dd");
    }/*from www.j a v a 2 s  . co m*/

    public static Date formatDate(String date) {
        return format(date, "yyyy-MM-dd");
    }

    public static String format(Date date) {
        return format(date, "yyyy-MM-dd HH:mm:ss");
    }

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

    public static Date format(String date) {
        Date dt = format(date, "yyyy-MM-dd HH:mm:ss");
        if (dt == null) {
            return formatDate(date);
        } else {
            return dt;
        }
    }

    public static Date format(String date, String format) {
        SimpleDateFormat df = new SimpleDateFormat(format);
        try {
            return df.parse(date);
        } catch (ParseException e) {
            return null;
        }
    }
}

Related

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