Search code examples
javastringdatesimpledateformatdate-formatting

Convert Date string into another string with different format


I'm quite new to the Java and for the use case I would like to know how to convert String "2023-02-01" into "02012023" I had troubles understanding the correct usage of SimpleDateFormat for this case

So far I tried nothing


Solution

  • SimpleDateFormat is legacy now, try to use the modern java.time library instead:

    String newStringDate = LocalDate.parse("2023-02-01")
            .format(DateTimeFormatter.ofPattern("MMdduuuu"));