Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #28177 > unrolled thread
| Started by | mike <mikaelpetterson@hotmail.com> |
|---|---|
| First post | 2014-04-22 05:38 -0700 |
| Last post | 2014-04-22 06:57 -0700 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.java.programmer
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
| From | mike <mikaelpetterson@hotmail.com> |
|---|---|
| Date | 2014-04-22 05:38 -0700 |
| Subject | convert "01-Apr-08.12:38:04" to Date object |
| Message-ID | <74faf831-a90b-45d3-ae0e-18971856d9fc@googlegroups.com> |
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?
//mike
[toc] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2014-04-22 09:03 -0400 |
| Message-ID | <lj5pbg$33s$1@dont-email.me> |
| In reply to | #28177 |
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
[toc] | [prev] | [next] | [standalone]
| From | mike <mikaelpetterson@hotmail.com> |
|---|---|
| Date | 2014-04-22 06:57 -0700 |
| Message-ID | <d5341610-73c0-459e-92c8-415bd5388271@googlegroups.com> |
| In reply to | #28178 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web