Set MessageFormat to Locale.US : Message Format « I18N « Java Tutorial






import java.text.MessageFormat;
import java.util.Date;
import java.util.Locale;

public class MessageFormatReuse {
  public static void main(String args[]) {
    String pattern = "{0}K was deleted on {1}.";
    MessageFormat formatter = new MessageFormat(pattern);

    Double kb = new Double(3.5);
    Date today = new Date();
    Object[] arguments = { kb, today };

    formatter.setLocale(Locale.US);
    System.out.println(formatter.format(arguments));
  }
}








13.12.Message Format
13.12.1.Use MessageFormat to format a sentence
13.12.2.Date Number Sample
13.12.3.Substitute tokens in a String
13.12.4.Formatting a Message Containing a Number
13.12.5.Format message with Integer fillers
13.12.6.Use a custom format
13.12.7.Floating point numbers
13.12.8.Currency number format
13.12.9.Percent value format
13.12.10.Formatting a Message Containing a Time
13.12.11.Format Date() in short format
13.12.12.Format Date() value in medium format
13.12.13.Format Date() in long
13.12.14.Format Date value in full length
13.12.15.Use a custom format for Date value
13.12.16.Formatting a Message Containing a Date
13.12.17.Combine date value in a sentence
13.12.18.Set MessageFormat to Locale.US