Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #12538
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe07.iad.POSTED!83aa503d!not-for-mail |
|---|---|
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Date parsing always returning the month of January |
| References | <e81b9b48-9f62-4958-8dbb-3a44f73187c4@c21g2000yqi.googlegroups.com> |
| In-Reply-To | <e81b9b48-9f62-4958-8dbb-3a44f73187c4@c21g2000yqi.googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Lines | 30 |
| Message-ID | <H8t3r.14467$vo2.13610@newsfe07.iad> (permalink) |
| X-Complaints-To | abuse@newsrazor.net |
| NNTP-Posting-Date | Wed, 29 Feb 2012 17:21:43 UTC |
| Date | Wed, 29 Feb 2012 09:21:41 -0800 |
| X-Received-Bytes | 1886 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:12538 |
Show key headers only | View raw
On 2/29/12 8:46 AM, laredotornado wrote:
> 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?
The "DD" should be "dd". "DD" is "Day of Year", so this is saying its
the first day of the year. "dd" is "Day of Month".
Often, when I'm having trouble with date parsing or formatting, its
because I made a mistake on the format string. The javadocs fix my
mistake in seconds.
HTH,
Daniel.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
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