Java Hour Format formatDate(Date date, String dateFormat)

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

Description

format Date

License

Apache License

Declaration

public static String formatDate(Date date, String dateFormat) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String DATE_FORMAT = "yyyy-MM-dd";
    public static final String CMS_DRAW_SEQUENCE_FORMAT = "yyyyMMddHHmmss";

    public static String formatDate(Date date) {
        return formatDate(date, DATE_FORMAT);
    }//from  w  w  w .j a  v a 2s.  co  m

    public static String formatDate(Date date, String dateFormat) {
        try {
            return new SimpleDateFormat(dateFormat).format(date);
        } catch (Exception e) {
            return "";
        }
    }

    public static Date formatDate(String date) {
        return parseDate(date, CMS_DRAW_SEQUENCE_FORMAT);
    }

    public static Date parseDate(String date) {
        return parseDate(date, DATE_FORMAT);
    }

    public static Date parseDate(String dateString, String dateFormat) {
        try {
            return new SimpleDateFormat(dateFormat).parse(dateString);
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. formatDate(Date d, String pattern, TimeZone tz)
  2. formatDate(Date d, TimeZone tz)
  3. formatDate(Date date, boolean includeTime)
  4. formatDate(Date date, boolean time, boolean csv)
  5. formatDate(Date date, boolean withTime)
  6. formatDate(Date date, String expression)
  7. formatDate(Date date, String format)
  8. formatDate(Date date, String format)
  9. formatDate(Date date, String format)