Dev - Parsing date string

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Dev - Parsing date string

byersa
Can someone tell me how to parse this JavaMail date string into a
Timestamp object?

Wed, 29 Mar 2006 19:49:18 -0700

Thanks,

-Al
 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - Parsing date string

BJ Freeman
I started with apache.james.mailet.dates to understand the task.

Adding to the date parsing problem are systems which produce dates
formatted in non-standard ways, such as Microsoft's email server which
writes out time zones in full ("Eastern Standard Time" instead of "EST"
or "-0500") and cause Timestamp.parse() to crash.

do not have definite code that works 100% of the time. Still testing.

Al Byers sent the following on 3/29/06 9:21 PM:

> Can someone tell me how to parse this JavaMail date string into a
> Timestamp object?
>
> Wed, 29 Mar 2006 19:49:18 -0700
>
> Thanks,
>
> -Al
>  
> _______________________________________________
> Dev mailing list
> [hidden email]
> http://lists.ofbiz.org/mailman/listinfo/dev
>
 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - Parsing date string

Jacopo Cappellato
In reply to this post by byersa
Al,

you can use the java.text.SimpleDateFormat class:

http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

The pattern you have to apply is this:

"EEE, d MMM yyyy HH:mm:ss Z"

So the code is:

String dateString = "Wed, 29 Mar 2006 19:49:18 -0700";
DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
Date parsedDate = df.parse(dateString, new ParsePosition(0));

Hope this helps,

Jacopo

Al Byers wrote:

> Can someone tell me how to parse this JavaMail date string into a
> Timestamp object?
>
> Wed, 29 Mar 2006 19:49:18 -0700
>
> Thanks,
>
> -Al
>  
> _______________________________________________
> Dev mailing list
> [hidden email]
> http://lists.ofbiz.org/mailman/listinfo/dev
>

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev