How to convert Date from dd-MMM-yyyy to dd-MM-yyyy in Java



172 views
How to convert Date from dd-MMM-yyyy to dd-MM-yyyy in Java
asked Oct 22, 2016 by avibootz

1 Answer

0 votes
import java.util.Date;
import java.util.Locale;

public class JavaApplication1 {

    public static void main(String[] args) {

        String str = "22-Oct-2016";
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
        try {
            Date dt = dateFormat.parse(str);
            dateFormat = new SimpleDateFormat("dd-MM-yyyy");
            System.out.println(dateFormat.format(dt));
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }      
    }
}
 
/*
 
run:
 
22-10-2016
 
*/

 



answered Oct 22, 2016 by avibootz

Related questions

1 answer 144 views
1 answer 151 views
1 answer 173 views
1 answer 178 views
1 answer 136 views
1 answer 131 views
...