0

I'm getting dates and trying to parse them into more readable dates but I keep getting a parse error, the formatting looks correct to me but its not working

 DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
 DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
    try {
        Date date1 = df.parse(purchase.getRedeem_at());

        String readableDate = df2.format(date1);

        b.append(readableDate);

    } catch (ParseException e) {

        e.printStackTrace();
    }

An example string im trying to parse is

2014-08-12T02:30:00Z
Brian
  • 4,328
  • 13
  • 58
  • 103

3 Answers3

2

You're missing the seconds part from your first format string.

DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
//                                                       ^
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
2

joda will parse this format right out of the box:

DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
DateTime ourDate = fmt.parseDateTime(jdkDate);

If you have further problems, do leave a comment.

Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82
hd1
  • 33,938
  • 5
  • 80
  • 91
1

You should add "ss"

DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); 
naveejr
  • 735
  • 1
  • 15
  • 31