Android Date Format formatDate(Date date, String dateFormat)

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

Description

Format date with `dateFormat` given and default locale `Locale.KOREA`

License

Open Source License

Parameter

Parameter Description
date a parameter
dateFormat a parameter

Declaration

public static String formatDate(Date date, String dateFormat) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;

public class Main {
    public static final String DATE_FORMAT = "yyyy-MM-dd G HH:mm:ss z";

    /**/*from   w  ww.  jav  a2s.  co  m*/
     * Format date with default `DATE_FORMAT` and default locale `Locale.KOREA`
     * @param date
     * @return
     */
    public static String formatDate(Date date) {
        return formatDate(date, DATE_FORMAT);
    }

    /**
     * Format date with `dateFormat` given and default locale `Locale.KOREA`
     * @param date
     * @param dateFormat
     * @return
     */
    public static String formatDate(Date date, String dateFormat) {
        return formatDate(date, dateFormat, Locale.ENGLISH);
    }

    /**
     * Format date
     * @param date
     *       `Date` formatted to
     * @param dateFormat
     *       Date format like 'yyyy-MM-dd'
     * @param locale
     *       Locale for date format.
     * @return
     *      Formatted date string 
     */
    public static String formatDate(Date date, String dateFormat,
            Locale locale) {
        SimpleDateFormat format = new SimpleDateFormat(dateFormat, locale);
        return format.format(date);
    }
}

Related

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