• Post Reply Bookmark Topic Watch Topic
  • New Topic

Deprecated method and parsing rfc2822 date.  RSS feed

 
Jan Andersson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to parse a RFC 2822 formated string into Date object. The deprecated Date constructor can do this. However since this is deprecated I'd rather use SimpleDateFormat, which doesn't work.



What am I doing wrong here? Is there another way to parse the pretty standard RFC2822 date format?

Thanks!
[ January 10, 2008: Message edited by: Jan Andersson ]
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what is going on, but your snippet runs fine without exception and with the correct result?
It should, the format is also mentioned in the javadoc of the SimpleDateFormat class.
 
Jan Andersson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very odd!

That exact snippet gives me:


Would the Locale make any difference?
Version maybe... very unlikely

java.vm.version=1.5.0_12-b04
java.vm.vendor=Sun Microsystems Inc.

 
Paul Clapham
Sheriff
Posts: 22829
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jan Andersson:
Would the Locale make any difference?
You're in Sweden, so maybe it would. Try this:or Locale.UK maybe.
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, the Locale is important. It is needed to parse the string for the days and the months. In Swedish, december is probably not abbriviated as Dec.
When I explicitly set the Locale to French for example, I got the exception you mention.
 
Jan Andersson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks!
works:
SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.ENGLISH);

Pretty obvious now :/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!