Java Hour Format formatDate(Date date, String format)

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

Description

Format date by the format

License

Open Source License

Parameter

Parameter Description
date - the source date
format - the date format

Return

the result String

Declaration

public static String formatDate(Date date, String format) 

Method Source Code


//package com.java2s;

import java.text.Format;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public final static String DEFAULT_DATE_FORMAT = "yyyyMMddHHmmss";

    public static String formatDate(Date date) {
        if (date == null) {
            return null;
        }//from w  ww  .  ja  v a 2  s  .c  o  m

        Format formatter = new SimpleDateFormat(DEFAULT_DATE_FORMAT);
        return formatter.format(date);
    }

    /**
     * Format date by the format
     * @param date - the source date
     * @param format - the date format
     *
     * @return the result String
     */
    public static String formatDate(Date date, String format) {
        if (date == null) {
            return null;
        }

        Format formatter = new SimpleDateFormat(format);
        return formatter.format(date);
    }
}

Related

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