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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:26:56+00:00 2026-06-14T22:26:56+00:00

I am just starting with Java (Android) and got stuck on a Date formatting

  • 0

I am just starting with Java (Android) and got stuck on a Date formatting issue.
I have a small Form where you can enter a project name and choose a Start date on a Calendar. The Startdate and Projectname gets than entered into the database, after that the pre-defined Tasks get than entered automatically into the database.

  • Task 1 Due Date is Startdate,
  • Task 2 is the Startdate plus x days = DueDate2,
  • Task 3 is The DueDate2 plus x days = DueDate3

I have now come up with the below Sourcecode and everything works besides that I get the wrong Format of my Date. For some reason, my Format is correct in newDateStr, but when I parse it again to be a Date Object, the format changes and is than incorrect. I can’t see my mistake, anyone can help?

My understanding is:

  1. Set the Date format of the date entered (curFormat)
  2. Set the target Date format (postFormater)
  3. Parse your Date which is a String at this time, to turn it into a date Object (use curFormat)
  4. Format this date to get target date format (use postFormater), now its a String again
  5. Parse this again to get it back to be a date which is needed for the calendar
  6. Use calendar instance, setTime(here the formated date) and add the x days
  7. Format the Date to get target date format (use postFormater), now its a String again
  8. Because I need a Date Object again, I have to parse it again.

    // The format of your input date string
    SimpleDateFormat curFormater = new SimpleDateFormat("MM/dd/yyyy"); 
    
    // The format of your target date string
    SimpleDateFormat postFormater = new SimpleDateFormat("dd-MM-yyyy"); 
    
    // The calendar instance which adds a locale to the date
    Calendar cal = Calendar.getInstance();
    
    // Parse the string (pro.getStart()) to return a Date object 
    Date dateObj = curFormater.parse(pro.getStart()); 
    
    // Format the Date dd-MM-yyyy
    String newDateStr = postFormater.format(dateObj);
    
    // Parse the string to return a Date object
    Date Startdate = postFormater.parse(newDateStr);
    
    while (cur.isAfterLast() == false) 
    {
        Integer delayTime = cur.getInt(cur.getColumnIndex("DelayTime"));    
    if (flag == false)
    {
        dateInString = Startdate;
        flag = true;
    }else{
        cal.setTime(dateInString);
        // add the extra days
        cal.add(Calendar.DAY_OF_MONTH, delayTime);
        // Format the Date dd-MM-yyyy
        newDateStr =  postFormater.format(cal.getTime()); 
        // Parse the string to return a Date object
        dateInString =  postFormater.parse(newDateStr);
    
    
    Log.i("newDateStr Format",newDateStr.toString()); // 29-11-2012
    Log.i("dateInString parse",dateInString.toString()); // Thu Nov 29 00:00:00 GMT 2012
    

I hope someone sees my mistake. Thank you very much in advance !

  • 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-14T22:26:57+00:00Added an answer on June 14, 2026 at 10:26 pm

    A java.util.Date object does not have any format in it or memory of the format you used to parse it. The output of its toString method, and hence what you get as output from dateInString.toString() will always be in the default JDK format that you are seeing: Thu Nov 29 00:00:00 GMT 2012

    You have to use a formatter to convert it into a formatted string whenever you want to display it. You cannot “Format the Date object” so to say. (UI frameworks tend to have built in facilities for doing this automatically.)

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

Sidebar

Related Questions

I'm just starting out on android and my java is verry rusty. I can't
as someone's who's just starting to get into Android/Java programming, I've read the docs
I am just starting Java RMI and have some problems with when to use
I'm just starting out with learning Java, and have run into a problem. When
I'm just starting out on Android and Java programming, coming in from a C++
I have starting learning Java and android application development side-by-side. Currently, I a String-array
I'm a flash developer with no previous Java experience, just starting to learn android
I'm just starting in Java and i'm stuck on something really annoying. I'm using
Can someone help me please.. just starting java..:( How can I display all possible
I'm just starting out in Java, and only ever used PHP before - finding

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.