Java Locale Format formatDate(Date date, String format, String localeText)

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

Description

format Date

License

Open Source License

Declaration

public static String formatDate(Date date, String format, String localeText) 

Method Source Code

//package com.java2s;
/*//from   ww  w  . ja v a 2s  .  c  om
 * Keystone Development Framework
 * Copyright (C) 2004-2009 Rick Knowles
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public License
 * Version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License Version 2 for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * Version 2 along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

public class Main {
    public static String formatDate(Date date, String format, String localeText) {
        String localeLanguage = null;
        String localeCountry = null;

        if ((localeText == null) || localeText.equals("") || (localeText.indexOf('_') == -1)) {
            localeLanguage = "en";
            localeCountry = "US";
        } else {
            localeLanguage = localeText.substring(0, localeText.indexOf('_'));
            localeCountry = localeText.substring(localeText.indexOf('_') + 1);
        }

        DateFormat sdf = new SimpleDateFormat(format, new Locale(localeLanguage, localeCountry));

        return sdf.format(date);
    }
}

Related

  1. formatBytesForDisplay(long amount)
  2. formatComma(String number)
  3. formatDate(Calendar cal, String format)
  4. formatDate(Date date, String format)
  5. formatDate(Date date, String format)
  6. formatDate(Date date, String pattern)
  7. formatDate(Date date, String pattern)
  8. formatDate(Date date, String pattern, Locale locale)
  9. formatDate(Date date, String pPatern)