How to convert yyyy-mm-dd to mm-dd-yyyy in Java

1 Answer

0 votes
import java.util.Date;
import java.text.SimpleDateFormat;

public class MyClass {
    public static void main(String args[]) throws Exception {  
        SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-mm-dd");
        SimpleDateFormat outputFormat = new SimpleDateFormat("mm-dd-yyyy");
        
        Date date = inputFormat.parse("2023-11-05");
        
        String output = outputFormat.format(date);
        
        System.out.println(output);  
    }
}



/*
run:

11-05-2023

*/

 



answered Nov 5, 2023 by avibootz

Related questions

1 answer 144 views
1 answer 151 views
1 answer 173 views
1 answer 137 views
...