Java Date Format formatDate(Date date)

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

Description

format Date

License

Open Source License

Declaration

public static String formatDate(Date 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   w  w w .  j  a v a2s .c  om

    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(Date date)
  2. formatDate(Date date)
  3. formatDate(Date date)
  4. formatDate(Date date)
  5. formatDate(Date date)
  6. formatDate(Date date)
  7. formatDate(Date date)
  8. formatDate(Date date)
  9. formatDate(Date date)