Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to format logfile in YYYYMMDD format?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading