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 8341849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:36:21+00:00 2026-06-09T05:36:21+00:00

I have a date that is in the MM/dd/yy format. I get it from

  • 0

I have a date that is in the MM/dd/yy format. I get it from an XML file. Let’s say, for example, it’s 10/03/11.

I execute the following code on it:

try {
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    System.out.println("dateStr: " + dateStr);
    date = sdf.parse(dateStr);
    System.out.println("dateStr After: " + sdf.format(date));
} catch(Exception e) {
    System.out.println("Error when formatting date");
}

The output is:

dateStr: 10/03/11
dateStr After: 10/03/0011

I can not seem to get it to be 10/03/2011. Any ideas why?

  • 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-06-09T05:36:22+00:00Added an answer on June 9, 2026 at 5:36 am

    When the date you are parsing has year with two chars, your simpleDateFormatter should also yy only.

    EDIT:

    // First convert to date object
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy");
    System.out.println("dateStr: " + dateStr);
    
    Date date = sdf.parse(dateStr);
    
    SimpleDateFormat sdf2 = new SimpleDateFormat("MM/dd/yyyy");
    sdf2.format(date);
    
    // Then, format it to get 2011 with another date format.
    System.out.println("dateStr After: " + sdf.format(date));
    System.out.println("dateStr NEXT After: " +  sdf2.format(date));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a date that I can represent in a culture-invariant format
I have a date that I get from a server formatted in EST like
I have a date format that I am getting from the database and is
I have get the date from excel sheet using POI using the below code,
I have a date and I would like to format the date like that:
I have a Date format: 2009-08-10T16:03:03Z that I want to convert to: @MMM dd,
I have a stored procedure that returns data in the format of: Date |
I have an xml file that contains a list of items i can deserialize
I'm parsing this date format from XML:=> 2011-12-06T07:41:14.016+00:00 , and I'm getting this error:
I'm parsing an XML file from an external source, and I have 2 attributes

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.