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


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

Re: convert "01-Apr-08.12:38:04" to Date object

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: convert "01-Apr-08.12:38:04" to Date object
Date Tue, 22 Apr 2014 09:03:42 -0400
Organization A noiseless patient Spider
Lines 34
Message-ID <lj5pbg$33s$1@dont-email.me> (permalink)
References <74faf831-a90b-45d3-ae0e-18971856d9fc@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Tue, 22 Apr 2014 13:03:44 +0000 (UTC)
Injection-Info mx05.eternal-september.org; posting-host="bd4e1cba8d8592bec5d5ed9e4537fbfd"; logging-data="3196"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19fqcXza+K6kLnZwq4RLAIR"
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0
In-Reply-To <74faf831-a90b-45d3-ae0e-18971856d9fc@googlegroups.com>
Cancel-Lock sha1:F0pYlK1f8iY4qTRzFc98ew9aM1U=
Xref csiph.com comp.lang.java.programmer:28178

Show key headers only | View raw


On 4/22/2014 8:38 AM, mike wrote:
> Hi,
>
> How can I convert this:
>
> String time = "01-Apr-08.12:38:04";
>
> SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy'.'hh:mm:ss ");
>
> try {
> Date date = dateFormat.parse(time);
> } catch (ParseException e) {
> e.printStackTrace();
>
> }
>
> I get the following:
>
> java.text.ParseException: Unparseable date: "01-Apr-08.12:38:04"
> 	at java.text.DateFormat.parse(DateFormat.java:337)
>
>
> Any ideas on how I can work around this?

     As you've constructed it, `dateFormat' requires a trailing space,
but `time' doesn't have one.

     Also, I'm not too sure that using "hh" without an AM/PM indicator
is a good idea.  It's possible that parse() objects to the ambiguity.


-- 
Eric Sosman
esosman@comcast-dot-net.invalid

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

convert "01-Apr-08.12:38:04" to Date object mike <mikaelpetterson@hotmail.com> - 2014-04-22 05:38 -0700
  Re: convert "01-Apr-08.12:38:04" to Date object Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-04-22 09:03 -0400
    Re: convert "01-Apr-08.12:38:04" to Date object mike <mikaelpetterson@hotmail.com> - 2014-04-22 06:57 -0700

csiph-web