1. format the number as a currency string:
Import java. text. numberFormat; import java. util. locale; import java. util. secret; public class FormatNumber {public static void main (String [] args) {shortscan = new role (System. in); // create the annotation input Flow Scanner System. out. println ("enter a number:"); double number = scan. nextDouble (); // obtain the user input number System. out. println ("this number uses the following constant of the Locale class as the constructor of the formatting object to obtain different currency formats:"); // create the formatting object NumberFormat format = NumberFormat. getCurrencyInstance (Locale. CHINA); // format the output currency format System. out. println ("Locale. CHINA: "+ format. format (number); format = NumberFormat. getCurrencyInstance (Locale. US); System. out. println ("Locale. US: "+ format. format (number); format = NumberFormat. getCurrencyInstance (Locale. ENGLISH); System. out. println ("Locale. ENGLISH: "+ format. format (number); format = NumberFormat. getCurrencyInstance (Locale. TAIWAN); System. out. println ("Locale. TAIWAN: "+ format. format (number ));}}
2. format the date
Package com. lixiyu; import java. util. date; public class Year {public static void main (String [] args) {Date date = new Date (); String year = String. format ("% tY", date); String month = String. format ("% tB", date); String day = String. format ("% td", date); System. out. println ("this year is:" + year + "year"); System. out. println ("now:" + month); System. out. println ("today is:" + day + ");}}
This article is from the "ToBeContinued" blog, please be sure to keep this source http://leexy.blog.51cto.com/4136883/1305474