Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #12544

Re: Date parsing always returning the month of January

From Jim Janney <jjanney@shell.xmission.com>
Newsgroups comp.lang.java.programmer
Subject Re: Date parsing always returning the month of January
Date 2012-02-29 15:30 -0700
Organization the cement's just for the weight, dear
Message-ID <2pwr751de8.fsf@shell.xmission.com> (permalink)
References <e81b9b48-9f62-4958-8dbb-3a44f73187c4@c21g2000yqi.googlegroups.com>

Show all headers | View raw


laredotornado <laredotornado@zipmail.com> writes:

> Hi,
>
> I'm using Java 6.  Hoping someone can see the simple error I have
> missed.  I'm trying to parse a date.  I have
>
> 		final String formattedStr = "2012-03-01 01:30:00";
> 		final String format = "yyyy-MM-DD HH:mm:ss";
> 		final SimpleDateFormat sdf = new SimpleDateFormat(format);
> 		try {
> 			ret = sdf.parse(formattedStr);
> 		} catch (ParseException e) {
> 			e.printStackTrace();
> 		}
> 		String retStr = ret.toString();
>
> The value of "retStr" is "Sun Jan 01 01:30:00 CST 2012".  In fact, the
> month of the date string is always getting converted to January, even
> though above it shoudl be March.  Where is my date parsing going
> wrong?

This is only indirectly related to your question, but I recommend
calling setLenient(false) any time you use a DateFormat for parsing.
Too easy to get bogus results otherwise.

-- 
Jim Janney

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar


Thread

Date parsing always returning the month of January laredotornado <laredotornado@zipmail.com> - 2012-02-29 08:46 -0800
  Re: Date parsing always returning the month of January markspace <-@.> - 2012-02-29 09:20 -0800
    Re: Date parsing always returning the month of January Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-02-29 09:22 -0800
      Re: Date parsing always returning the month of January markspace <-@.> - 2012-02-29 11:17 -0800
  Re: Date parsing always returning the month of January Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-02-29 09:21 -0800
  Re: Date parsing always returning the month of January Jim Janney <jjanney@shell.xmission.com> - 2012-02-29 15:30 -0700

csiph-web