Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.util.Formatter: UnknownFormatConversionException: Conversion = 'F'

What's wrong with

public String toString() {
    return super.toString()
            + String.format(" %1$F-%2$F", startDate, endDate);
}

I get

Caused by: java.util.UnknownFormatConversionException: Conversion = 'F' at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2606) at java.util.Formatter$FormatSpecifier.(Formatter.java:2634) at java.util.Formatter.parse(Formatter.java:2480) at java.util.Formatter.format(Formatter.java:2414) at java.util.Formatter.format(Formatter.java:2367) at java.lang.String.format(String.java:2769)

I wanted to print the ISO 8601 date defined in java.util.Formatter

like image 367
rds Avatar asked Jan 15 '23 08:01

rds


1 Answers

I think the date formatting patterns require a prefix:

't', 'T'    date/time   Prefix for date and time conversion characters. See Date/Time Conversions. 

The example for the F modifier also shows this syntax:

'F'     ISO 8601 complete date formatted as "%tY-%tm-%td". 

So the following pattern should work:

String.format(" %1$tF-%2$tF", startDate, endDate);
like image 176
Jörn Horstmann Avatar answered Feb 19 '23 21:02

Jörn Horstmann