Java 字符串格式化
Format Specifier Data Type Output %a floating point (except BigDecimal) Returns Hex output of floating point number. %b Any type “true” if non-null, “false” if null %c character Unicode character %d integer (incl. byte, short, int, long, bigint) Decimal Integer %e floating point decimal number in scientific notation %f floating point decimal number %g floating point decimal number, possibly in scientific notation depending on the precision and value. %h any type Hex String of value from hashCode() method. %n none Platform-specific line separator. %o integer (incl. byte, short, int, long, bigint) Octal number %s any type String value %t Date/Time (incl. long, Calendar, Date and TemporalAccessor) %t is the prefix for Date/Time conversions. More formatting flags are needed after this. See Date/Time conversion below. %x integer (incl. byte, short, int, long, bigint) Hex string.
String template = "日期%s年%s月%s日" ;
String year = new SimpleDateFormat ( "yyyy" ) . format ( new Date ( ) ) ;
String month = new SimpleDateFormat ( "MM" ) . format ( new Date ( ) ) ;
String day = new SimpleDateFormat ( "dd" ) . format ( new Date ( ) ) ;
System. out. println ( String. format ( template, year, month, day) ) ;
Java String format()