List of usage examples for java.util Locale US
Locale US
To view the source code for java.util Locale US.
Click Source Link
From source file:Main.java
public static void main(String args[]) { int style = DateFormat.MEDIUM; // Also try with style = DateFormat.FULL and DateFormat.SHORT Date date = new Date(); DateFormat df;/*from w w w . ja v a 2 s.c o m*/ df = DateFormat.getDateInstance(style, Locale.UK); System.out.println("United Kingdom: " + df.format(date)); df = DateFormat.getDateInstance(style, Locale.US); System.out.println("USA: " + df.format(date)); df = DateFormat.getDateInstance(style, Locale.FRANCE); System.out.println("France: " + df.format(date)); df = DateFormat.getDateInstance(style, Locale.ITALY); System.out.println("Italy: " + df.format(date)); df = DateFormat.getDateInstance(style, Locale.JAPAN); System.out.println("Japan: " + df.format(date)); }
From source file:NumFormat.java
public static void main(String[] av) { int data[] = { 100, 1000, 10000, 1000000 }; NumberFormat nf = NumberFormat.getInstance(Locale.US); for (int i = 0; i < data.length; ++i) { System.out.println(data[i] + "\t" + nf.format(data[i])); }// w w w .j a v a 2s.c o m }
From source file:Test.java
public static void main(String[] args) { BigDecimal value = new BigDecimal(12345); Locale.setDefault(Locale.JAPAN); System.out.printf("Default locale: %s\n", Locale.getDefault().getDisplayName()); NumberFormat nf = NumberFormat.getCurrencyInstance(); String formattedCurrency = nf.format(value); System.out.printf("%s\n", formattedCurrency); nf.setCurrency(Currency.getInstance(Locale.US)); formattedCurrency = nf.format(value); System.out.printf("%s\n\n", formattedCurrency); Locale.setDefault(Locale.US); System.out.printf("Default locale: %s\n", Locale.getDefault().getDisplayName()); nf = NumberFormat.getCurrencyInstance(); formattedCurrency = nf.format(value); System.out.printf("%s\n", formattedCurrency); nf.setCurrency(Currency.getInstance("JPY")); formattedCurrency = nf.format(value); System.out.printf("%s\n\n", formattedCurrency); Locale.setDefault(Locale.FRANCE); System.out.printf("Default locale: %s\n", Locale.getDefault().getDisplayName()); nf = NumberFormat.getCurrencyInstance(); formattedCurrency = nf.format(value); System.out.printf("%s\n", formattedCurrency); nf.setCurrency(Currency.getInstance("USD")); formattedCurrency = nf.format(value); System.out.printf("%s\n\n", formattedCurrency); }
From source file:ConstantLocaleUsage.java
public static void main(String[] argv) { NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setParseIntegerOnly(false); double usersNumber; if (argv.length == 1) try {//from w ww. ja va 2 s .c o m usersNumber = numberFormat.parse(argv[0]).doubleValue(); } catch (ParseException e) { usersNumber = 197912.29; } else usersNumber = 1976.0826; numberFormat = NumberFormat.getNumberInstance(Locale.US); System.out.println("User's number (US): " + numberFormat.format(usersNumber)); numberFormat = NumberFormat.getNumberInstance(Locale.GERMANY); System.out.println("User's number (GERMANY): " + numberFormat.format(usersNumber)); numberFormat = NumberFormat.getNumberInstance(); System.out.println("User's number (DEFAULT LOCALE): " + numberFormat.format(usersNumber)); }
From source file:MainResourceBundle.java
public static void main(String[] args) { ResourceBundle bundle = MainResourceBundle.getBundle("hello", Locale.US); System.out.println(bundle.getString("hello")); }
From source file:MainClass.java
public static void main(String args[]) { Date date = new Date(); DateFormat df;//from w w w . j ava 2 s. com df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.JAPAN); System.out.println("Japan: " + df.format(date)); df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.KOREA); System.out.println("Korea: " + df.format(date)); df = DateFormat.getDateInstance(DateFormat.LONG, Locale.UK); System.out.println("United Kingdom: " + df.format(date)); df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US); System.out.println("United States: " + df.format(date)); }
From source file:MainClass.java
public static void main(String[] args) { Date today = new Date(); Locale[] locales = { Locale.US, Locale.UK, Locale.GERMANY, Locale.FRANCE }; int[] styles = { DateFormat.FULL, DateFormat.LONG, DateFormat.MEDIUM, DateFormat.SHORT }; DateFormat fmt;//from w ww .j av a2 s . co m String[] styleText = { "FULL", "LONG", "MEDIUM", "SHORT" }; // Output the date for each local in four styles for (int i = 0; i < locales.length; i++) { System.out.println("\nThe Date for " + locales[i].getDisplayCountry() + ":"); for (int j = 0; j < styles.length; j++) { fmt = DateFormat.getDateInstance(styles[j], locales[i]); System.out.println("\tIn " + styleText[j] + " is " + fmt.format(today)); } } }
From source file:JFormattedTextFieldDateInputSampleDateFormatFULLLocaleUS.java
public static void main(String args[]) { JFrame frame = new JFrame("Date/Time Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label;/* www. j a v a 2s. c o m*/ JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format fullUSDate = DateFormat.getDateInstance(DateFormat.FULL, Locale.US); label = new JLabel("Full US date:"); input = new JFormattedTextField(fullUSDate); input.setValue(new Date()); input.setColumns(20); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.add(new JTextField()); frame.pack(); frame.setVisible(true); }
From source file:MainResourceBundle.java
public static void main(String[] args) { // create a new ResourceBundle with specified locale ResourceBundle bundle = MainResourceBundle.getBundle("hello", Locale.US); // print the keys Enumeration<String> enumeration = bundle.getKeys(); while (enumeration.hasMoreElements()) { System.out.println(enumeration.nextElement()); }/* w ww . j a v a 2s .com*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { String host = "host"; int port = 25; String from = "from@from.net"; String toAddr = "to@to.net"; Socket servSocket = new Socket(host, port); DataOutputStream os = new DataOutputStream(servSocket.getOutputStream()); DataInputStream is = new DataInputStream(servSocket.getInputStream()); if (servSocket != null && os != null && is != null) { os.writeBytes("HELO\r\n"); os.writeBytes("MAIL From:" + from + " \r\n"); os.writeBytes("RCPT To:" + toAddr + "\r\n"); os.writeBytes("DATA\r\n"); os.writeBytes("X-Mailer: Java\r\n"); os.writeBytes(/* w ww . jav a2 s . co m*/ "DATE: " + DateFormat.getDateInstance(DateFormat.FULL, Locale.US).format(new Date()) + "\r\n"); os.writeBytes("From:" + from + "\r\n"); os.writeBytes("To:" + toAddr + "\r\n"); } os.writeBytes("Subject:\r\n"); os.writeBytes("body\r\n"); os.writeBytes("\r\n.\r\n"); os.writeBytes("QUIT\r\n"); String responseline; while ((responseline = is.readUTF()) != null) { if (responseline.indexOf("Ok") != -1) break; } }