Java Utililty Methods Locale Format

List of utility methods to do Locale Format

Description

The list of methods to do Locale Format are organized into topic(s).

Method

Stringformat(String format, Date date, Locale locale)
format
if (date == null)
    return ("");
SimpleDateFormat dateFormatter = null;
if (locale == null)
    dateFormatter = new SimpleDateFormat(format);
else
    dateFormatter = new SimpleDateFormat(format, locale);
return (dateFormatter.format(date));
...
Stringformat(String message, Object[] params)
Apply printf() like formatting to a string.
int currentParamNumber = 0;
StringBuffer formattedMessage = new StringBuffer();
for (int i = 0; i < message.length(); i++) {
    if (message.charAt(i) == '%') {
        if (currentParamNumber >= params.length) {
            formattedMessage.append("?missing data?");
        } else if ((params[currentParamNumber] instanceof Number) && (i + 1 < message.length())) {
            i += matchOptionalFormatting((Number) params[currentParamNumber++], message.substring(i + 1),
...
Stringformat(String pattern, Date date)
Formats the specific date into the given pattern
return getSimpleDateFormat(pattern).get().format(date);
Stringformat12(final long ticks)
format
return formatDate(ticks, SDFTwelve);
StringformatAdena(long amount)
Format the specified digit using the digit grouping symbol "," (comma).
For example, 123456789 becomes 123,456,789.
synchronized (ADENA_FORMATTER) {
    return ADENA_FORMATTER.format(amount);
StringformatAdena(long amount)
Return amount of adena formatted with "," delimiter
return formatNumber(amount);
DateformatarDataArquivoStr(String data)
Formata uma data de arquivo inserindo as barras no formato "dd/MM/yyyy"
StringBuffer buffer = new StringBuffer(data);
buffer.insert(2, '/');
buffer.insert(5, '/');
Date dataArquivo = null;
try {
    if (!data.equals("00000000")) {
        dataArquivo = getData(buffer.toString());
} catch (ParseException e) {
    e.printStackTrace();
return dataArquivo;
StringformatarNumeroBr(Double numero)
formatar Numero Br
initNumberFormat();
return formatador.format(numero);
StringformataValor(Double valor)
formata Valor
NumberFormat nf = NumberFormat.getInstance(new Locale(LOCALE_LANGUAGE, LOCALE_COUNTRY));
nf.setMinimumFractionDigits(2);
nf.setMaximumFractionDigits(2);
nf.setMinimumIntegerDigits(1);
return nf.format(valor);
StringformatBytes(final long bytes)
Pretty output of bytes, "1023 bytes", "1.1 kb", "523 kb", "1.7 Mb", "143 Gb" etc.
if (bytes < KILO_BYTES) {
    return String.valueOf(bytes) + " bytes";
if (bytes < MEGA_BYTES) {
    BigDecimal no = new BigDecimal(bytes).divide(KB_BD, 1, BigDecimal.ROUND_HALF_UP);
    if (no.longValue() >= 100) {
        no = no.setScale(0, BigDecimal.ROUND_HALF_UP);
    return NumberFormat.getInstance(Locale.getDefault()).format(no) + " kb";
if (bytes < GIGA_BYTES) {
    BigDecimal no = new BigDecimal(bytes).divide(MB_BD, 1, BigDecimal.ROUND_HALF_UP);
    if (no.longValue() >= 100) {
        no = no.setScale(0, BigDecimal.ROUND_HALF_UP);
    return NumberFormat.getInstance(Locale.getDefault()).format(no) + " Mb";
BigDecimal no = new BigDecimal(bytes).divide(GB_BD, 1, BigDecimal.ROUND_HALF_UP);
if (no.longValue() >= 100) {
    no = no.setScale(0, BigDecimal.ROUND_HALF_UP);
return NumberFormat.getInstance(Locale.getDefault()).format(no) + " Gb";