If you carefully read the documentation on formatted output in Java, you can find the following lines:
The following syntax can be used:
%[argument_index$][flags][width]conversion
The optional argument_index flags and width are defined as above.
The required conversion is a two character sequence. The first character is 't' or 'T'. The second character indicates the format to be used. It is not necessary to follow the GNU date and POSIX strftime (3c).
The date format is indicated by two characters: the actual %t
, indicating that the parameter should be interpreted as a date, and flags indicating in what format the date should be displayed. For example, the following code displays the date according to the current locale:
System.out.printf("%tD", new Date());
The documentation provides a complete list of date formatting flags.
If you don’t have a tough condition to use in the System.out.printf
code, then you should pay attention to the SimpleDateFormat
class, which allows for more flexible and readable customization of the display of dates.