| printf(String format, Object... o) |
| String.format(String format, Object... o) |
| e.g. |
|
Calendar c = Calendar.getInstance();
String s = String.format("Time: %1$tH:%1$tM", c) |
| flags | |
| - | (hyphen)left justified |
| + | always include sign |
| (space) include leading space | |
| 0 | zero padded |
| , | include locale specific grouping separators |
| ( | enclose negative numbers in parentheses |
| width | minimum number of characters |
| conversion: | this is always two characters beginning with t or T |
| e.g. %n platform specific new line |
| flags | |
| b or B | Boolean e.g. true or TRUE |
| h or H | Hashcode, null or Integer.toHexString(arg.hashCode()) |
| s or S | Null or if arg implements Formattable arg.formatTo() else arg.toString() |
| c or C | Unicode character |
| d | Decimal |
| o | Octal |
| x or X | Hexidecimal |
| e or E | Scientific |
| f | Floating point |
| g or G | Decimal or scientific depending on precision and value after rounding |
| a or A | Hexidecimal floating with significand and exponent |
| flags | |
| B | Full month name |
| h or b | 3 character month name |
| A | Locale specific full weekday name |
| a | Locale specific short weekday name |
| C | Century |
| Y | 4 digit year |
| y | 2 digit year |
| j | Day of year |
| m | 2 digit month number |
| d | 2 digit day of month number |
| e | 1 or 2 digit day of month number |
| flags | |
| H | Hour 24hr |
| I | Hour 12hr (2 digits) |
| k | Hour 12hr (1 or 2 digits) |
| M | Minute (2 digits) |
| S | Second (2 digits) |
| L | Millisecond (3 digits) |
| N | Nanosecond (9 digits) |
| p or P | am/pm or AM/PM |
| z | GMT offset |
| Z | Timezone |
| s | Seconds since 1/1/1970 |
| Q | Milliseconds since 1/1/1970 |
| flags | |
| tR | %tH:%tM |
| tT | %tH:%tM:%tS |
| tr | %tI:%tM:%tS %tP |
| tD | %tm/%td/%tY |
| tF | %tY-%tm-%td |
| tc | %ta %tb %td %tT %tZ %tY |