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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:21:34+00:00 2026-05-31T22:21:34+00:00

I’m trying to convert an input date string to a date format and then

  • 0

I’m trying to convert an input date string to a date format and then to a datetime format.
As a test, I gave an input of an incorrect date format, but this doesn’t seem to be throwing any parse exceptions and gives me the wrong output. Any thoughts on what my code below is doing wrong?

            String OLD_FORMAT ="MM/dd/yyyy";
            String NEW_FORMAT ="yyyyMMdd HHmmss";
            SimpleDateFormat sdf = new SimpleDateFormat(OLD_FORMAT);
            String oldDateString = "03/01211/2012"; //Incorrect input
            Date myOldDate;
            Datetime myNewDate;
            try {
                myOldoldDate = sdf.parse(oldDateString); 
           //Returns Wed Jun 24 00:00:00 IST 2015...why?? 
          //Shouldn't this be throwing a parse exception?
            } catch (ParseException e) {
                logger.error("Error while parsing Date");
            }
            sdf.applyPattern(NEW_FORMAT);
            //Converting date to datetime format
            try {
                myNewDate= DateHelper.toDatetime(sdf.parse((sdf.format(myOldDate)))); 
           //Returns 2015-06-24 00:00:00.0
            } catch (ParseException e) {
                logger.error("Error while parsing Date");
            }
  • 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-31T22:21:35+00:00Added an answer on May 31, 2026 at 10:21 pm

    “03/01211/2012” => Jun 24 00:00:00 IST 2015 … why?

    My guess is that June 24th, 2015 is 1211 days from March 1st, 2012.
    Excessive rollover, reads it as March 1211th.

    You should be able to turn this off with:

    sdf.setLenient(false)
    

    public void setLenient(boolean lenient)

    Specify whether or not date/time interpretation is to be lenient. With lenient interpretation, a date such as “February 942, 1996” will be treated as being equivalent to the 941st day after February 1, 1996. With strict interpretation, such dates will cause an exception to be thrown.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.