

Milliseconds since epoch Jan 1, 1970 00:00:00 UTC. Nanosecond formatted with 9 digits and leading 0s e.g. Minute within the hour formatted a leading 0 e.g. Hour of the day for the 12-hour click without a leading 0 e.g.

Hour of the day for the 24 hour clock without a leading 0 e.g. “ 01” – “ 12“.ĭay of the year formatted with leading 0s e.g. Hour of the day for the 12-hour clock e.g. Hour of the day for the 24-hour clock e.g. ISO 8601 formatted date with “ %tY-%tm-%td“. “ 01” to “ 31“.ĭay of the month formatted without a leading 0 e.g. “ Fri Feb 17 07:45:“ĭay of the month formatted with two digits. “00” through “99”.ĭate and time formatted with “ %ta %tb %td %tT %tZ %tY” e.g. “ Jan“, “ Feb“, etc.Ĭentury part of year formatted with two digits e.g. “ January“, “ February“, etc.Ībbreviated month name e.g. “ Sun“, “ Mon“, etc.įull name of the month e.g. “ Sunday“, “ Monday“Ībbreviated name of the week day e.g. Flagįull name of the day of the week, e.g. Note: Using the formatting characters with “%T” instead of “%t” in the table below makes the output uppercase. More formatting flags are needed after this. %t is the prefix for Date/Time conversions. long, Calendar, Date and TemporalAccessor) Hex String of value from hashCode() method.ĭate/Time (incl. byte, short, int, long, bigint)ĭecimal number, possibly in scientific notation depending on the precision and value. Here is a quick reference to all the conversion specifiers supported: Specifier you can continue to append data to sbuf here. StringBuilder sbuf = new StringBuilder() Output formatted using the format() method will be appended to the StringBuilder. ("My name is: %s%n", "joe") Ĭreate a Formatter and link it to a StringBuilder. String output = String.format("%s = %d", "joe", 35) įor formatted console output, you can use printf() or the format() method of System.out and System.err PrintStreams. If there were a “java sprintf” then this would be it. The most common way of formatting a string in java is using String.format(). You may also want to take a look at What's New in Java 8 from Pluralsight or 38 Java String-Related Techniques Making Your Life Easier, a course on Udemy. This guide is an attempt to bring some clarity and ease the usage of string formatting in Java. While it does include all the information, the organization leaves something to be desired. Have you tried to read and understand Java’s String format documentation? I have and found it nearly impenetrable. When you purchase through links on our site, we may receive an affiliate commission.
