I would appreciate if you could help me to achieve a conversion from DateTime format (08/30/2018) to this type of String "August 30, 2018". I am working with refreshes and I would like to show on a TextView something like that. Thank you
            Asked
            
        
        
            Active
            
        
            Viewed 93 times
        
    -1
            
            
        - 
                    Where is your code? Post it here and let us know what issues you are facing there – B001ᛦ Oct 26 '18 at 13:18
- 
                    will you do some effort before asking question – Ajay Chauhan Oct 26 '18 at 13:37
- 
                    https://stackoverflow.com/questions/5683728/convert-java-util-date-to-string – Ajay Chauhan Oct 26 '18 at 13:37
- 
                    @AjayChauhan I did dear friend. Just asking in english is a big one. Thank you for the link, although does not respond my question. Regards – JJeset BC Oct 26 '18 at 13:45
4 Answers
1
            
            
        Use this code for conversion:
SimpleDateFormat inputFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());
SimpleDateFormat outputFormat = new SimpleDateFormat("MMMM dd, yyyy", Locale.getDefault());
Date date;
String result = "";
try {
    date = inputFormat.parse("set your input date here");
    result = outputFormat.format(date); // here will be output date
} catch (e: ParseException) {
    Log.e("Error", "Parse exception", e);
}
 
    
    
        Jeel Vankhede
        
- 11,592
- 2
- 28
- 58
0
            
            
        try this
 String date ="2017-05-05 13:58:50 ";
            SimpleDateFormat input = new SimpleDateFormat("MM/dd/yyyy");
            SimpleDateFormat output = new SimpleDateFormat("MMMM dd,yyyy");
            try {
                 Date oneWayTripDate = input.parse(date);  // parse input
            } catch (ParseException e) {
                e.printStackTrace();
           }
 
    
    
        AhmetAcikalin
        
- 328
- 2
- 7
0
            
            
        This
String d = "08/30/2018";
LocalDate date = LocalDate.parse(d, DateTimeFormatter.ofPattern("MM/dd/yyyy"));
String newDate = date.format(DateTimeFormatter.ofPattern("MMMM dd, yyyy"));
System.out.println(newDate);
will print
August 30, 2018
Edit if you want to take into account lower apis, you can do this:  
String d = "08/30/2018";
String newDate = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    LocalDate date = LocalDate.parse(d, DateTimeFormatter.ofPattern("MM/dd/yyyy"));
    newDate = date.format(DateTimeFormatter.ofPattern("MMMM dd, yyyy"));
} else {
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    Date date = null;
    try {
        date = sdf.parse(d);
        sdf = new SimpleDateFormat("MMMM dd, yyyy");
        newDate = sdf.format(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
}
 
    
    
        forpas
        
- 160,666
- 10
- 38
- 76
- 
                    It seems that it's requires API level 26, and my current min is 19. Any suggestion? – JJeset BC Oct 26 '18 at 13:34
0
            
            
        Use this sample:
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm dd/MM/yyyy"); Date now = new Date(); String time = sdf.format(now);
 
    
    
        Tru Nguyen
        
- 11
- 2
