Re: Fw: How to date type conversion between xml and Java
Jack Bush <[email protected]>
| Newsgroups | gmane.comp.java.jdom.general |
|---|---|
| Message-ID | <[email protected]> |
Thank you to both Jason & Tatu,
Below is an attempt which I haven't yet being able to verify even though it has
been deployed in EJB 3.0 (Glassfish 2.1) container:
org.jdom.Element collectionDateTime =
((org.jdom.Element)area_element).getChild("collection_date_and_time");
SimpleDateFormat collection_date_formatter = new
SimpleDateFormat("dd/MM/yyyy");
Date collection_date_parsed =
collection_date_formatter.parse(collectionDateTime.getTextNormalize());
futureStock.setCollectionDate(collection_date_parsed);
SimpleDateFormat collection_time_formatter = new SimpleDateFormat("hh:mm:ss
a");
Date collection_time_parsed =
collection_time_formatter.parse(collectionDateTime.getTextNormalize());
futureStock.setCollectionTime(collection_time_parsed);
I am awaiting to test out the JPA persistent once the
"java.io.UTFDataFormatException" issue is resolved.
Thanks again,
Jack
----- Original Message ----
From: Tatu Saloranta <[email protected]>
To: Jack Bush <[email protected]>; Jason Hunter <[email protected]>
Cc: [email protected]
Sent: Tue, 17 August, 2010 5:03:14 AM
Subject: Re: [jdom-interest] Fw: How to date type conversion between xml and
Java
--- On Sun, 8/15/10, Jason Hunter <[email protected]> wrote:
> From: Jason Hunter <[email protected]>
> Subject: Re: [jdom-interest] Fw: How to date type conversion between xml and
>Java
> To: "Jack Bush" <[email protected]>
...
> Use java.text.SimpleDateFormat.
> It can parse the date string, lets you interact with it as
> data, and helps you reformat it if you need.
>
> Note it's relatively slow because of its complex
> internals. If your dates are always in the exact same
> simple format like you showed, and you need to parse a huge
> number of them, a simple custom parser based on character
> positions can be much faster.
Also, might want to consider Joda library, which is an improvement over JDK
defaults, both in functionality and (I think) with respect to efficiency. Can
usually just construct DateTime out of typical (ISO-8601) date Strings.
-+ Tatu +-
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/[email protected]