Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5981767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:59:24+00:00 2026-05-22T21:59:24+00:00

I want to use joda to parse datetime strings in emails. Unfortunately I get

  • 0

I want to use joda to parse datetime strings in emails. Unfortunately I get all kinds of different formats, for example

Wed, 19 Jan 2011 12:52:31 -0600
Wed, 19 Jan 2011 10:15:34 -0800 (PST)
Wed, 19 Jan 2011 20:03:48 +0000 (UTC)
Wed, 19 Jan 2011 17:02:08 -0600 (CST)
Fri, 21 Jan 2011 10:39:55 +0100 (CET)
Fri, 21 Jan 2011 17:50:42 -0500 (EST)
Wed, 06 Apr 2011 15:38:25 GMT
Thu, 7 Apr 2011 11:38:24 +0200 
Fri,  8 Apr 2011 05:13:36 -0700 (MST)
20 Apr 2011 03:00:46 -0400

The code below catches most of the variants but not all (for example, when there are two spaces instead of one, when the comma is missing etc.). And it looks just awkward.

Is there a more elegant way to handle this? Please advise.

            DateTimeParser[] parsers = {
                    DateTimeFormat.forPattern("E, d MMM y HH:mm:ss Z").getParser(),
                    DateTimeFormat.forPattern("E, d MMM y HH:mm:ss Z '(CET)'").getParser(),
                    DateTimeFormat.forPattern("E, d MMM y HH:mm:ss Z '(CST)'").getParser(),
                    DateTimeFormat.forPattern("E, d MMM y HH:mm:ss Z '(CEST)'").getParser(),
                    DateTimeFormat.forPattern("E, d MMM y HH:mm:ss Z '(GMT)'").getParser(),
                    DateTimeFormat.forPattern("E, d MMM y HH:mm:ss Z '(MST)'").getParser(),
                    DateTimeFormat.forPattern("E, d MMM y HH:mm:ss Z '(PST)'").getParser(),
                    DateTimeFormat.forPattern("E, d MMM y HH:mm:ss Z '(UTC)'").getParser(),
                    DateTimeFormat.forPattern("E, d MMM y HH:mm:ss Z '(EST)'").getParser(),
                    DateTimeFormat.forPattern("E, d MMM y HH:mm:ss Z '(EDT)'").getParser(),
                    DateTimeFormat.forPattern("E, d MMM y HH:mm:ss Z '(CDT)'").getParser(),
            };
            DateTimeFormatter inputFormatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter();

            try {
                calendar = inputFormatter.withLocale(Locale.US).parseDateTime(date[0]);
            }
            catch(Exception e) {
                System.out.println("problem with " + date[0]);
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:59:25+00:00Added an answer on May 22, 2026 at 9:59 pm

    Outside of using Joda’s DateTimeParser yourself and essentially parsing the text yourself building up a valid DateTime (which i think would be a lot of work), i don’t think there’s really much wrong with your approach. I do think that you have too many formats though. I think your set of formats could be reduced to:

     DateTimeParser[] parsers = {
         DateTimeFormat.forPattern("E, d MMM y HH:mm:ss Z").getParser(),
         DateTimeFormat.forPattern("E, d MMM y HH:mm:ss Z '('z')'").getParser(),
         DateTimeFormat.forPattern("E, d MMM y HH:mm:ss z").getParser(),
         DateTimeFormat.forPattern("dd MMM y HH:mm:ss Z").getParser(),
     };
    

    Z (Capital-Z) is the RFC 822 numeric timezone and small-z is the acronym for the timezone, like PDT, for example. This is still (on average) 2 exceptions thrown per parse request but if this doesn’t need to be high-performance, that’s probably not so bad.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is my stored procedure. I want use stored procedure select all row of
I have a Joda-DateTime field in my model and want to display it formatted
Example I want use the_excerpt in two locations. On functions.php I add function new_excerpt_length($length)
I want use localized strings from resources in xsl template as in aspx page,
I want use 1000 separator(,) for numeric values. how can i format strings with
I want use php curl with oauth to get the JSON data from twitter
I want use $.ajax get a url string from a xml file ,then with
I want use php simple xml parse some tree like this. how to plus
I use UITableView and I want change the height of different cells. But I
I want use groovy findAll with my param to filtering closure filterClosure = {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.