I need to get the date in the following format: YYYYMMDD
Have code which outputs below result.
[2023-02-13 11:05:03] [SEVERE ] sever message
System.setProperty("java.util.logging.SimpleFormatter.format",
"[%1$tF %1$tT] [%4$-7s] %5$s %n");
But I wanted to be like this [20230213 11:05:03] [SEVERE ] sever message
>Solution :
To change the format of the date to YYYYMMDD, you need to modify the value of the "java.util.logging.SimpleFormatter.format" property.
Try changing it to the following:
System.setProperty("java.util.logging.SimpleFormatter.format", [%1$tY%1$tm%1$td %1$tT] [%4$-7s] %5$s %n");
In this format, %1$tY will give you the 4-digit year, %1$tm will give you the 2-digit month, and %1$td will give you the 2-digit day. This way, the date will be displayed in the desired format.