Java Parse Date parseDateToString(final Date date, final String dateFormat, final String lang)

Here you can find the source of parseDateToString(final Date date, final String dateFormat, final String lang)

Description

Parses a date to a particular format and returns the formatted String .

License

Mozilla Public License

Parameter

Parameter Description
date the Date to parse
dateFormat the date format
lang the language/locale

Return

a date formatted according to the date format and locale

Declaration

public static String parseDateToString(final Date date, final String dateFormat, final String lang) 

Method Source Code

//package com.java2s;
/**//from   w ww.jav a2 s.c om
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 */

import com.google.common.base.Preconditions;

import java.text.SimpleDateFormat;
import java.util.Date;

import java.util.Locale;

public class Main {
    /**
     * Parses a date to a particular format and returns the formatted {@link String}.
     * @param date the {@link Date} to parse
     * @param dateFormat the date format
     * @param lang the language/locale
     * @return a date {@link String} formatted according to the date format and locale
     */
    public static String parseDateToString(final Date date, final String dateFormat, final String lang) {
        Preconditions.checkNotNull(date);
        Preconditions.checkNotNull(dateFormat);
        Preconditions.checkNotNull(lang);

        final Locale locale = new Locale(lang);
        final SimpleDateFormat format = new SimpleDateFormat(dateFormat, locale);

        return format.format(date);
    }
}

Related

  1. parseDateTimeString(String dateTimeString)
  2. parseDateToStr(Date date)
  3. parseDateToString(Date date, String format)
  4. parseDateToString(Date date, String pattern)
  5. parseDateToString(Date datetime)
  6. parseDateValue(String value)
  7. parseDateWithFormat(String date, SimpleDateFormat dateFormat, Date defaultDate)
  8. parseDateWithLeniency(final String str, final Locale locale, final String[] parsePatterns, final boolean lenient)
  9. parseDateWithoutTime(final String date)