title: Converting a String to Date, almost done!
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2201925/converting-iso8601-compliant-string-to-java-util-date">Converting ISO8601-compliant String to java.util.Date</a>  </p>
  </blockquote>
  
  
  
  <p>I'm trying to convert this String:</p>
  
  <pre><code>2011-06-07T14:08:59.697-07:00
  </code></pre>
  
  <p>To a Java Date, so far, here's what I did:</p>
  
  <pre><code>SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S");
  Date date1 = sdf.parse("2011-06-07T14:08:59.697", new java.text.ParsePosition(0));
  </code></pre>
  
  <p>Almost everything is good, except the most important part, the <strong>timezone</strong> !!
  The problem with <a href="http://download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html#rfc822timezone" rel="nofollow noreferrer">SimpleDateFormat</a> is that it expect a TimeZone in <code>+/-hhmm</code> and mine is in <code>+/-hh:mm</code> format.</p>
  
  <p>Also, and I don't know why, this works:</p>
  
  <pre><code>SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S Z");
  Date date1 = sdf.parse("2011-06-07T14:08:59.697 -0700", new java.text.ParsePosition(0));
  </code></pre>
  
  <p>But this does not (the space before the timezone):</p>
  
  <pre><code>SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SZ");
  Date date1 = sdf.parse("2011-06-07T14:08:59.697-0700", new java.text.ParsePosition(0));
  </code></pre>
  
  <p>What is the correct format to transform this date <code>2011-06-07T14:08:59.697-07:00</code> to a java date ?</p>
  
  <p>Thanks for your help!</p>