Java Parse Date parseDate(Date date, String pattern)

Here you can find the source of parseDate(Date date, String pattern)

Description

parse Date

License

Apache License

Declaration

public static String parseDate(Date date, String pattern) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

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

    public static String parseDate(Date date, String pattern) {
        if (date == null) {
            return null;
        }//  ww w .j a  v a2 s.co  m
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(pattern);
            return sdf.format(date);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public static String parseDate(Date date) {
        if (date == null) {
            return null;
        }
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
            return sdf.format(date);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }
}

Related

  1. parseDate(Date date)
  2. parseDate(Date date)
  3. parseDate(Date date)
  4. parseDate(Date date, int style, Locale local, boolean withTime)
  5. parseDate(Date date, String format)
  6. parseDate(DateFormat df, String dateStr)
  7. parseDate(DateFormat f, String date)
  8. parseDate(final Date date)
  9. parseDate(final String date)