[jdom-interest] Fw: How to date type conversion between xml and Java

Jack Bush netbeansfan at yahoo.com.au
Wed Aug 18 00:54:46 PDT 2010


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 <cowtowncoder at yahoo.com>
To: Jack Bush <netbeansfan at yahoo.com.au>; Jason Hunter <jhunter at servlets.com>
Cc: jdom-interest at jdom.org
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 <jhunter at servlets.com> wrote:

> From: Jason Hunter <jhunter at servlets.com>
> Subject: Re: [jdom-interest] Fw: How to date type conversion between xml and 
>Java
> To: "Jack Bush" <netbeansfan at yahoo.com.au>
...
> 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 +-


      




More information about the jdom-interest mailing list