Java Date Format dateFormat(String date, String dateFormat)

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

Description

date Format

License

Open Source License

Declaration

public static Date dateFormat(String date, String dateFormat) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static Date dateFormat(String date, String dateFormat) {
        if (date == null)
            return null;
        SimpleDateFormat format = new SimpleDateFormat(dateFormat);
        if (date != null)
            try {
                return format.parse(date);
            } catch (Exception ex) {
            }/*from   ww w.j  a  v  a2s  .  c  o m*/
        return null;
    }

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

    public static String dateFormat(Date date, String dateFormat) {
        if (date == null)
            return "";
        SimpleDateFormat format = new SimpleDateFormat(dateFormat);
        if (date != null)
            return format.format(date);

        return "";
    }

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

Related

  1. dateFormat(Date date, String pattern)
  2. dateFormat(DateFormat f, Date d)
  3. dateFormat(int grain, TimeZone timeZone)
  4. dateFormat(java.util.Date date, String formatStr)
  5. dateFormat(long time)
  6. DateFormat(String dateStr, String oldPattern, String newPattern)
  7. dateformat(String dateTime)
  8. dateFormat(String datetime)
  9. dateFormat(String df, TimeZone timeZone)