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


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

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

Newsgroups comp.lang.java.programmer
Date 2014-04-22 06:57 -0700
References <74faf831-a90b-45d3-ae0e-18971856d9fc@googlegroups.com> <lj5pbg$33s$1@dont-email.me>
Message-ID <d5341610-73c0-459e-92c8-415bd5388271@googlegroups.com> (permalink)
Subject Re: convert "01-Apr-08.12:38:04" to Date object
From mike <mikaelpetterson@hotmail.com>

Show all headers | View raw


Den tisdagen den 22:e april 2014 kl. 15:03:42 UTC+2 skrev Eric Sosman:
> 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

Hi,

yes I unintentionally added a space at the end and of course I should use HH.

Thanks alot.

//mike

Back to comp.lang.java.programmer | Previous | Next — Previous 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