Java yyyy formatDateString(java.util.Date date, String format)

Here you can find the source of formatDateString(java.util.Date date, String format)

Description

Convert a date to required String format.

License

Open Source License

Parameter

Parameter Description
date Given date.
format Given String ("dd-MM-yyyy" for 01-01-2000 format "dd-MMM-YYYY" for 01-Jan-2000 format)

Return

Date in required format.

Declaration

public static String formatDateString(java.util.Date date, String format) 

Method Source Code


//package com.java2s;

import java.text.*;

public class Main {
    /**/*from   ww  w  .  j  a  v a 2  s.co  m*/
     * Convert a date to required String format.
     *
     * @param date Given date.
     * @param format Given String ("dd-MM-yyyy" for 01-01-2000 format
     * "dd-MMM-YYYY" for 01-Jan-2000 format)
     *
     * @return Date in required format.
     */
    public static String formatDateString(java.util.Date date, String format) {
        if ((date == null) || (format == null)) {
            return null;
        }

        // Set the date
        SimpleDateFormat fm = new SimpleDateFormat(format);
        return fm.format(date);
    }
}

Related

  1. formatDate2ShortStr(Date date)
  2. formatDate2Str(Date date)
  3. formatDateAsShortDateLocalTime(Date moonDate, TimeZone tz)
  4. formatDateFromStringToString(String str)
  5. formatDateNoTime(Date date)
  6. formatDateToString(Date d)
  7. formatDateToString(String strDate)
  8. formatDicomDate(String dicomDate)
  9. formatearDateToString(Date date)