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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:03:59+00:00 2026-06-02T00:03:59+00:00

String date=12/20/20102; SimpleDateFormat df = new SimpleDateFormat(dd/MM/yyyy); Date today; try { today = df.parse(date.trim());

  • 0
String date="12/20/20102";
        SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");           
             Date today;
            try {
                today = df.parse(date.trim());
              Log.e("Error", "Correct");
            } catch (java.text.ParseException e) {
                // TODO Auto-generated catch block
                Log.e("Error", "InCorrect");
            } 

I am not able to get this corrected. I always get this converted and if I give an incorrect date string also it not catching in the exception.

Please help me.

  • 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-02T00:04:00+00:00Added an answer on June 2, 2026 at 12:04 am

    Your string input is :

    String date="12/20/20102";
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); 
    

    Two mistakes:

    1. String date = “12/20/20122“; // it shoud be “12/20/2012“

    2. Your String input is in MM/dd/yyyy format and you trying to parse in dd/MM/yyyy format. Change your string input format (20/12/2012) OR change formatter to (MM/dd/yyyy).

    EDIT

    Here is sample code for validating user input date in dd/MM/yyyy format.

    String str = txt.getText().toString();
    
                try{
                String tmp[] = str.split("/");
                int day = Integer.parseInt(tmp[0]);
                int month = Integer.parseInt(tmp[1]);
                int year = Integer.parseInt(tmp[2]);
    
                    if(!(day > 31) && !(month > 12) && (tmp[2].length() == 4) )
                    {
                        // Verified date....
                    }
                    else
                    {
                        Toast.makeText(getBaseContext(), "Please enter date in correct format. (dd/MM/yyy)", Toast.LENGTH_SHORT).show();
                    }
                }
                catch (Exception e) {
                    Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_SHORT).show();
                }
    

    Note: Leap year and February month logic is not implemented.

    Full validation with all conditions available here.
    http://www.mkyong.com/regular-expressions/how-to-validate-date-with-regular-expression/

    And don’t forget to accept this if it helps you.

    Thanks…

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

Sidebar

Related Questions

String date = new java.text.SimpleDateFormat(MM-dd-yyyy).format(new java.util.date()); upload.uploadfile(192.168.0.210, muruganp, vm4snk, /home/media/Desktop/FTP Upload/+date+_RB.zip, /fileserver/filesbackup/Emac/+date+_RB.zip); uploadfile is
I'm getting the error java.lang.ClassCastException: java.util.Date at avb.Test.main(Test.java:38) SimpleDateFormat(yyyy-MM-dd HH:mm:ss.SSS) from the code DateFormat
I am using this code to parse a Date. SimpleDateFormat formatter = new SimpleDateFormat(MM/dd/yyyy);
I have the following code: SimpleDateFormat dateFormat = new SimpleDateFormat(yyyy-dd-MM HH:mm:ss); Date convertedDate; String
I'm trying an example: DateFormat df = new SimpleDateFormat(MM/dd/yyyy); String date = 03/09/2010; //30
The code String strDate = 2010-12-01; SimpleDateFormat sdf = new SimpleDateFormat(yyyy-mm-dd); Date parsedDate =
I'm using java.text.SimpleDateFormat to parse strings of the form yyyyMMdd . If I try
I have string Tue Nov 12 2010,I want to parse it in java.util.Date object.
I am trying to convert a string to proper date format using Java's SimpleDateFormat
Hi i am trying to parse a string into a java.sql.date Here is what

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.