user468311
user468311

Reputation:

Get date/time with SimpleDateFormat

folks! I've got such date entry:

<pubDate>23/06/2011 11:57</pubDate>

I try to parse it:

mDateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm");
item_tag.getChild("pubDate").setEndTextElementListener(new EndTextElementListener() {

            @Override
            public void end(String body) {
                date= new GregorianCalendar(0,0,0).getTime();
                try {
                    date=mDateFormat.parse(body);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        });

But I get something like that: 23/57/2011 11:57 I get minutes instead of month value What's wrong with my code?

Upvotes: 0

Views: 1075

Answers (2)

piotrpo
piotrpo

Reputation: 12636

Your code looks OK. Check out what do you really pass to this method, or just check what will happen if you insert line like:

body = "23/06/2011 11:57";

Upvotes: 1

Egor
Egor

Reputation: 40203

As shown in examples here, you should use '-' instead of '/' when instantiating a mask.

Upvotes: 0

Related Questions