title: Format Date Java
body: <p>How to format a string that looks like this  </p>
  
  <blockquote>
    <p>Sat Dec 08 00:00:00 JST 2012</p>
  </blockquote>
  
  <p>into yyyy-mm-dd i.e. </p>
  
  <blockquote>
    <p>2012-12-08</p>
  </blockquote>
  
  <p>From browsing the <a href="http://www.mkyong.com/java/how-to-convert-string-to-date-java/" rel="nofollow">web</a>, I found this piece of code:</p>
  
  <pre><code>SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
      String dateInString = "Sat Dec 08 00:00:00 JST 2012";
  
      try {
  
          Date date = formatter.parse(dateInString);
          System.out.println(date);
          System.out.println(formatter.format(date));
  
      } catch (ParseException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>However, I am unable to modify it to accept the first line (Sat Dec 08 00:00:00 JST 2012) as a string and format that into the yyyy-mm-dd format. </p>
  
  <p>What should I do about this? Should I be attempting to modify this? Or try another approach altogether?</p>
  
  <p>Update: I'm using this from your answers <strong>(getting error: Unparseable date: "Sat Dec 08 00:00:00 JST 2012")</strong></p>
  
  <pre><code>public static void main(String[] args) throws ParseException{
          SimpleDateFormat srcFormatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.JAPANESE);
          SimpleDateFormat destFormatter = new SimpleDateFormat("dd-MMM-yyyy", Locale.JAPANESE);
          Date date = srcFormatter.parse("Sat Dec 08 00:00:00 JST 2012");
          String destDateString = destFormatter.format(date);
         /* String dateInString = "Sat Dec 08 00:00:00 JST 2012";*/
          System.out.println(destDateString);
  
          /*try {
  
              Date date = formatter.parse(dateInString);
              System.out.println(date);
              System.out.println(formatter.format(date));
  
          } catch (ParseException e) {
              e.printStackTrace();
          }*/
      }
  }
  </code></pre>