title: Fastest way to parse a YYYYMMdd date in Java
body: <p>When parsing a YYYYMMdd date, e.g. 20120405 for 5th April 2012, what is the fastest method?</p>
  
  <pre><code>int year = Integer.parseInt(dateString.substring(0, 4));
  int month = Integer.parseInt(dateString.substring(4, 6));
  int day = Integer.parseInt(dateString.substring(6));
  </code></pre>
  
  <p>vs.</p>
  
  <pre><code>int date = Integer.parseInt(dateString)
  year = date / 10000;
  month = (date % 10000) / 100; 
  day = date % 100;
  </code></pre>
  
  <p>mod 10000 for month would be because mod 10000 results in MMdd and the result / 100 is MM</p>
  
  <p>In the first example we do 3 String operations and 3 "parse to int", in the second example we do many things via modulo.</p>
  
  <p>What is faster? Is there an even faster method?</p>