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

The Archive Base Latest Questions

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

String temp_date=07/28/2011 11:06:37 AM; Date date = new Date(temp_date); //Depricated SimpleDateFormat sdf = new

  • 0
String temp_date="07/28/2011 11:06:37 AM";  
Date date = new Date(temp_date); //Depricated 
SimpleDateFormat sdf = new SimpleDateFormat("MMM-dd-yyyy hh:mm:ss"); 
String comp_date= sdf.format(date);
System.out.println(comp_date);

This works, But If I use something like this

String temp_date="07/28/2011 11:06:37 AM";  
try{  
    SimpleDateFormat sdf = new SimpleDateFormat("MMM-dd-yyyy hh:mm:ss"); 
    Date comp_date= sdf.parse(temp_date);
    System.out.println(comp_date);
}catch(Exception e){
    System.out.println(e);
}

This exception is thrown:

java.text.ParseException: Unparseable date: "07/28/2011 11:06:37 AM"
  • 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-24T08:06:22+00:00Added an answer on May 24, 2026 at 8:06 am

    Your parsing pattern is wrong. It does not match the date string representation. The MMM denotes a 3-letter localized month abbreviation, while you have 2-digit month number in your actual date, you need MM. You’ve also slashes / as date/month/year separator and not -. For the AM/PM marker you also need an a afterwards so that the right hh can be parsed.

    This should work:

    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a"); 
    

    For an explanation of those patterns, read the SimpleDateFormat javadoc.


    I believe that your concrete functional requirement is to convert the given date string as specified by the pattern MM/dd/yyyy hh:mm:ss a into another date string format, as specified by the pattern MMM-dd-yyyy hh:mm:ss. In that case, you should then have two SimpleDateFormat instances, one which parses the string in the given pattern to a Date and another which formats the parsed Date to the given pattern. This should do what you want:

    String inputDate = "07/28/2011 11:06:37 AM";
    Date date = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a").parse(inputDate);
    String outputDate = new SimpleDateFormat("MMM-dd-yyyy HH:mm:ss").format(date);
    System.out.println(outputDate); // Jul-28-2011 11:06:37
    

    Note that I changed hh in output to be HH because it would otherwise end up in 1-12 hour representation without an AM/PM marker. The HH represents it as 0-23 hour.

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

Sidebar

Related Questions

I want the date format as dd-MMM-yyyy. My code is: String v_date_str=Sun Mar 06
I cant quite figure out what the format should be to parse this date.
I can't understand why this few lines Date submissionT; SimpleDateFormat tempDate = new SimpleDateFormat(EEE
i have a date entry in yyyy-mm-dd format in mysql database. Using php i
I have code like this: string uriString = @C:\Temp\test.html; Uri uri = new Uri(uriString);
I need a function to check a date with boolean. I have a String
String strLine = ; try { BufferedReader b = new BufferedReader(new FileReader(html.txt)); strLine =
I am trying to produce a date from a string with the following: NSDateFormatter
I have an issue with date Formatter. I have Two string. one string contains
I have some code that tries to parse a date string. When I do

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.