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

StringformatBytes(long byteCount, Locale locale)
Converts a byte-count to a formatted string suitable for display to the user.
if (byteCount >= 1024 * 1024 * 1024) {
    NumberFormat gigaByteFormat = new DecimalFormat("0.00 GB", new DecimalFormatSymbols(locale));
    return gigaByteFormat.format((double) byteCount / (1024 * 1024 * 1024));
if (byteCount >= 1024 * 1024) {
    NumberFormat megaByteFormat = new DecimalFormat("0.0 MB", new DecimalFormatSymbols(locale));
    return megaByteFormat.format((double) byteCount / (1024 * 1024));
if (byteCount >= 1024) {
    NumberFormat kiloByteFormat = new DecimalFormat("0 KB", new DecimalFormatSymbols(locale));
    return kiloByteFormat.format((double) byteCount / 1024);
return byteCount + " B";
StringformatBytesForDisplay(long amount)
Takes a byte size and formats it for display with 'friendly' units.
double displayAmount = (double) amount;
int unitPowerOf1024 = 0;
if (amount <= 0) {
    return "0 B";
while (displayAmount >= 1024 && unitPowerOf1024 < 4) {
    displayAmount = displayAmount / 1024;
    unitPowerOf1024++;
...
StringformatComma(String number)
format Comma
return formatComma(Double.parseDouble(number));
StringformatDate(Calendar cal, String format)
Formats the date held in a Calendar using the current locale's timezone (not the calendar's own timezone).
return formatDate(cal.getTime(), format, localZone);
StringformatDate(Date date, String format)
format date
SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.US);
String sysdate = formatter.format(date);
return sysdate;
StringformatDate(Date date, String format)
format Date
SimpleDateFormat outFormat = new SimpleDateFormat(format);
return outFormat.format(date);
StringformatDate(Date date, String format, String localeText)
format Date
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);
...
StringformatDate(Date date, String pattern)
The date of Date type conversion, in accordance with the specified format to a String.
String result = null;
if (date == null || pattern == null) {
    return result;
try {
    result = getDateFormat(pattern).format(date);
} catch (Exception e) {
    result = null;
...
StringformatDate(Date date, String pattern)
Formats the given date according to the specified pattern.
if (date == null)
    throw new IllegalArgumentException("date is null");
if (pattern == null)
    throw new IllegalArgumentException("pattern is null");
SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.US);
formatter.setTimeZone(GMT);
return formatter.format(date);
StringformatDate(Date date, String pattern, Locale locale)
format Date
return new SimpleDateFormat(pattern, locale).format(date);