Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: Date parsing always returning the month of January Date: Wed, 29 Feb 2012 09:20:00 -0800 Organization: A noiseless patient Spider Lines: 30 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 29 Feb 2012 17:20:02 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="4160"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/xokIS97Ds4hTjE9NUU8hC90i2iqucfmU=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 In-Reply-To: Cancel-Lock: sha1:bNxxEbVkVbR3/NMnnLps6hgzdB0= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:12537 On 2/29/2012 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? First, good example, even though I could have used a complete compilable one. However, the answer is simple, and I'm going to have to ask you to re-read the documentation for SimpleDateFormat. You missed the meaning of one of those letters.