klreeher
klreeher

Reputation: 1615

wrong date in SimpleDateTime parse

This is the string that I have:

Sat, Nov 02, 2013 at 5:10 pm

I'm trying to parse it into a date time using this formatter:

DateFormat formatter = new SimpleDateFormat("EEE, MMM dd, YYYY 'at' K:mm a");

However, this is what it returns when I use it to parse the date string:

Sat Jan 05 17:10:00 CST 2013

I assume I'm getting the formatter wrong, but I can't figure out where.

Upvotes: 0

Views: 74

Answers (1)

rgettman
rgettman

Reputation: 178263

Capital YYYY is the format for something called the "week year". You want the lowercase yyyy for the actual year.

DateFormat formatter = new SimpleDateFormat("EEE, MMM dd, yyyy 'at' K:mm a");

With this change I output the parsed date and get:

Sat Nov 02 17:10:00 PDT 2013

(I'm in the Pacific time zone.)

Upvotes: 1

Related Questions