Formatting and parsing of Date and Strings in Java
<p>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. </p>

<ul>
<li>Task 1 Due Date is Startdate,</li>
<li>Task 2 is the Startdate plus x days = DueDate2,</li>
<li>Task 3 is The DueDate2 plus x days = DueDate3</li>
</ul>

<p>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?</p>

<p>My understanding is:</p>

<ol>
<li>Set the Date format of the date entered (curFormat)</li>
<li>Set the target Date format (postFormater)</li>
<li>Parse your Date which is a String at this time, to turn it into a date Object (use curFormat)</li>
<li>Format this date to get target date format (use postFormater), now its a String again</li>
<li>Parse this again to get it back to be a date which is needed for the calendar</li>
<li>Use calendar instance, setTime(here the formated date) and add the x days</li>
<li>Format the Date to get target date format (use postFormater), now its a String again</li>
<li><p>Because I need a Date Object again, I have to parse it again.</p>

<pre><code>// 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
</code></pre></li>
</ol>

<p>I hope someone sees my mistake. Thank you very much in advance !</p>
