For some reason, it is impossible to display the date in the line with the formatting character %t .

I'm trying like this:

 Date current1 = calGrig.getTime(); // получаем текущую дату System.out.printf ("текущая дата format 1: %t", format1.format(current1)); 

And it turns out only this way:

 System.out.println("текущая дата format 1: " + format1.format(current1)); 

    4 answers 4

    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.

      Sorry for the indiscreet question, but why do not you want to use the standard formatting class String?

       System.out.println(String.format("текущая дата format 1: %t",format1.format(current1)); 

        Use the class SimpleDateFormat http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

        In the Exmaples section you will see formats for every taste.

          Try

           System.out.printf ("текущая дата format 1: %s ", format1.format(current1)); 

          The fact is that format1.format (current1), since I suspect that format1 is something of type SimpleDateFormat, returns a String.