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

  • SEARCH
  • Home
  • 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 6323291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:29:24+00:00 2026-05-24T16:29:24+00:00

Here is my target format: 19 AUG 2011 And I try to convert this

  • 0

Here is my target format:

19 AUG 2011

And I try to convert this string to Calendar object by following code, but variable “date” remains null..

SimpleDateFormat formatter ; 
        Date date = null ; 
        formatter = new SimpleDateFormat("dd MMM yyyy");
        try {
         date = formatter.parse(returnDate);
    } catch (ParseException e) {            
        e.printStackTrace();
    } 
        Calendar cal=Calendar.getInstance();
        cal.setTime(date);

Does anyone know what’s going wrong? Thank You.

FYI, exception msg:

Unparseable date: “19 Aug 2011” at java.text.DateFormat.parse(Unknown
Source)

But I don’t think it is useful…

  • 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-24T16:29:25+00:00Added an answer on May 24, 2026 at 4:29 pm

    Something is going wrong with the parsing. You aren’t finding out about it because of this:

     catch (ParseException e) {            
    
     } 
    

    That’s basically saying, “I don’t care what goes wrong – ignore it.” At the very least you should be logging the error, and more likely letting the exception bubble up.

    Exceptions are an incredibly important diagnostic tool – don’t just catch them and ignore them.

    EDIT: Now that the question’s changed, we can see the exception – but the code is still continuing as if nothing’s happened. Even if you do want to mostly ignore the exception, you need to decide what value you want date to have if parsing failed. Clearly null is unhelpful – so you need to either let the exception bubble up (to let the caller know that parsing failed) or return some difference value (e.g. a default date, or today, or something like that).

    Now, as it happens, letting the exception bubble up makes the code simpler too. It doesn’t throw an exception on my machine, but maybe it will on yours:

    import java.util.*;
    import java.text.*;
    
    public class Test {
    
        public static void main(String[] args) throws Exception {
          Calendar cal = parseReturnDate("19 AUG 2011");
          System.out.println(cal);
        }
    
        public static Calendar parseReturnDate(String returnDate) 
            throws ParseException {
          SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy");
          Date date = formatter.parse(returnDate);
          Calendar cal=Calendar.getInstance();
          cal.setTime(date);
          return cal;
        }       
    }
    

    Note how we don’t need to declare variables separately to assigning them values, and that now we’re letting the exception bubble up we can just assign date its useful value directly.

    My guess is that your default time zone doesn’t use “AUG” as a short month name – but I can’t really tell without seeing the exception. If that’s the case, you might want to specify the locale when constructing the formatter:

    SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy",
                                                      Locale.US);
    

    You might also want to specify a time zone.

    (As an aside, Joda Time is a far superior API for date and time handling. If you’re doing any significant work with the value afterwards, I’d definitely recommend using it over Date/Calendar.)

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

Sidebar

Related Questions

Here's my code: UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(rightButtonPressed)]; [self.navigationItem setLeftBarButtonItem:leftButton]; [leftButton
An odd question this will be, but here goes. I have a page on
here the code found in this forum and i need to stored the 10
The target machine is running Ububtu server 8.04. Here's the tramp output: tramp: Opening
To give more information I am using the modular form here: http://jqueryui.com/demos/dialog/#modal-form `b(e.target).zIndex` is
Here is my code, which takes two version identifiers in the form 1, 5,
Here's a coding problem for those that like this kind of thing. Let's see
Here's the relevant code: Public class User.cs: public void FindByID(int id) { Parser parser
I'm trying to write some Elisp code to format a bunch of legacy files.
I currently have the following code to show a countdown to a specific date:

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.