Java Convert Date Format

I have date data with format "2019-08-25T13:45:13+00:00" and I'd like to convert it into more simple format such 25-Aug-2019

Here's the code:

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); 
String strDate = "";
try {
    //dateInString is variable contain : 2019-08-25T13:45:13+00:00 
    Date date1 = formatter.parse(dateInString.replaceAll("Z$", "+0000")); 
    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy");    
    strDate = dateFormat.format(date1); //you got the new date format on string
} catch (ParseException e) {
    e.printStackTrace(); 
}



Explanation about date format may be found at this link :
https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

Tidak ada komentar:

Posting Komentar