Java yyyy formatDate(Date unformattedDate, String format)

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

Description

Formats a give date with the supplied format

License

Open Source License

Parameter

Parameter Description
unformattedDate the date to be formated
format the format to be formated like dd/mm/yyyy or mm/dd/yy etc refer SimpleDateFormat for supported format.

Declaration

public static String formatDate(Date unformattedDate, String format) 

Method Source Code


//package com.java2s;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**// ww  w  . j  a  v  a  2  s . c  o  m
     * Formats a give date with the supplied format
     * @param unformattedDate the date to be formated
     * @param format the format to be formated like dd/mm/yyyy or mm/dd/yy etc 
     * refer SimpleDateFormat for supported format. 
     * @return
     */
    public static String formatDate(Date unformattedDate, String format) {
        String formattedDate = "";

        try {
            DateFormat df = DateFormat.getInstance();
            SimpleDateFormat sf = (SimpleDateFormat) df;
            sf.applyPattern(format);
            formattedDate = df.format(unformattedDate);

        } catch (RuntimeException e) {
            //LOG.log(Level.WARNING, "Error Formatting Date:" + unformattedDate);
        }
        return formattedDate;
    }
}

Related

  1. formatDate(Date date, String pattern)
  2. formatDate(Date date, String pattern)
  3. FormatDate(Date date, String sf)
  4. formatDate(Date date, TimeZone timeZone)
  5. formatDate(Date inputDate, String formatPattern)
  6. formatDate(DateTime aDateTime)
  7. formatDate(final Date date, final String defaultValue)
  8. formatDate(String date)
  9. formatDate(String date)