Java Hour Format formatDate(Date date, String format)

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

Description

format Date

License

Apache License

Declaration

public static String formatDate(Date date, String format) 

Method Source Code


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

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static DateFormat datefmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static String formatDate(Date date, String format) {
        if (date == null)
            return null;
        String str_date = null;/* w ww.  ja  v a2 s . com*/
        if (format != null) {
            DateFormat formater = new SimpleDateFormat(format);
            str_date = formater.format(date);
        } else {
            str_date = datefmt.format(date);
        }

        return str_date;
    }
}

Related

  1. formatDate(Date date, String dateFormat)
  2. formatDate(Date date, String expression)
  3. formatDate(Date date, String format)
  4. formatDate(Date date, String format)
  5. formatDate(Date date, String format)
  6. formatDate(Date date, String format)
  7. formatDate(Date date, String format, Locale locale)
  8. formatDate(Date date, String patter)
  9. formatDate(Date date, String pattern)