title: ISO8601 date string to Long in Android
body: <p>In my android app I pull the data from a ReST API which uses ISO8601 format for dates. One example is <code>"2014-04-24T21:56:50.443Z"</code>. Sometimes the timezone is denoted by Z and sometimes by <code>signHH:mm</code> (eg. -08:00). </p>
  
  <p>The dates that I receive from the api gets converted into long while the date gets inserted into my database. Currently I achieve this by using the following command in the <code>insert</code> statement which converts the iso8601String into Julian date which is subsequently converted into a long timestamp which gives the number of milliseconds since epoch (This was the only command I could come up with that would give me millisecond precision which is super important for my app)</p>
  
  <pre><code>"CAST(((strftime('%J', '" + iso8601String + "') - 2440587.5) * 86400000) AS INTEGER)"
  </code></pre>
  
  <p>Now a scenario has come up which demands me to convert the incoming iso8601String into its long timestamp even before it gets into database. The pattern that has to be supplied to Android's SimpleDateFormat to work with this string is <code>yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ</code>, but unfortunately <code>ZZZZZ</code> is not supported in android versions &lt; 4.3 (but I got to support all the devices running  >= 4.0 (api level 14))!!</p>
  
  <p>Is there anyway I can parse/format the iso8601String to and from timestamp without being dependent on <code>SimpleDateFormat</code>? (I can't use JodaTime as it a big dependency and also it is not known for its performance on android)</p>
  
  <p>The conversion will be done in my custom GSON serializer/de-serializer to convert <code>Date</code>s into <code>Long</code>s</p>