Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

String expiryDate = "2016-03-14";
private String formatDateTime(String expiryDate, String expiryTime) {
    SimpleDateFormat input = new SimpleDateFormat("yyyy-mm-dd");
    SimpleDateFormat output = new SimpleDateFormat("MMM, dd, yyyy");
    try {
        String formattedDate = output.format(input.parse(expiryDate ));// parse input
        return  formattedDate + ", " + expiryTime;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return null;
}

However when it returns it gives Jan, 14, 2016.

The desired output was Mar,14,2016

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
404 views
Welcome To Ask or Share your Answers For Others

1 Answer

mm should be capital MM. Beacuse

mm represent minute MM represent Month

So your format should be like

SimpleDateFormat input = new SimpleDateFormat("yyyy-MM-dd");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...