Dates from Strings in RFC822 format

D

Darren Davison

what's the simplest way to instantiate a java.util.Date given a
java.lang.String in RFC822 format?

i.e.

String d = "Wed, 23 Jul 2003 19:51:20 GMT";

Date date = [ new Date() based on above String]

I know I could parse it manually but it seems kludgy - I'd have expected
some inbuilt method in the java.[util|text].* hierarchy somewhere since
it's such an old and well used date format. Scanning the javadocs for
Date, DateFormat, Calendar et al didn't offer anything obvious - unless
I've missed it.

tia,
 
M

Manish Jethani

Darren said:
what's the simplest way to instantiate a java.util.Date given a
java.lang.String in RFC822 format?

i.e.

String d = "Wed, 23 Jul 2003 19:51:20 GMT";

Date date = [ new Date() based on above String]

javax.mail.internet.MimeMessage has a getDate method that
creates a java.util.Date off the rfc 822 Date header. Get a
kludge from there :)

-Manish
 
S

Shripathi Kamath

Darren Davison said:
what's the simplest way to instantiate a java.util.Date given a
java.lang.String in RFC822 format?

i.e.

String d = "Wed, 23 Jul 2003 19:51:20 GMT";

Date date = [ new Date() based on above String]

I know I could parse it manually but it seems kludgy - I'd have expected
some inbuilt method in the java.[util|text].* hierarchy somewhere since
it's such an old and well used date format. Scanning the javadocs for
Date, DateFormat, Calendar et al didn't offer anything obvious - unless
I've missed it.

tia,

Consider SimpleDateFormat.

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

Try "EEE, d MMM yyyy HH:mm:ss z". I haven't, so be warned

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top