title: Formatting a Date of type String using a Formatter Java
body: <p>Is it possible to do format a date of type String using a date formatter? I want to store my Date and Time in the Event class as Strings so that I don't need to convert the Strings loaded from a MYSQL database (using the types DATE and TIME) back into Date types so they can be stored in new Event objects. MySQL only accepts DATE in the format of <code>YYYY-MM-DD</code> and TIME in the format of <code>HH:MM:SS</code> but i want these to be formatted differently when i go to print them out in my program. </p>
  
  <p>When i run this code i get an <code>Cannot format given Object as a Date at java.text.DateFormat.format(Unknown Source)</code> error. If i try using parse() it won't compile because it only accepts Dates.</p>
  
  <p>Main class</p>
  
  <pre><code>public Main() {
     ArrayList&lt;Event&gt; events = new ArrayList&lt;Event&gt;();
     private SimpleDateFormat timeFormat = new SimpleDateFormat("HH:MM:SS");
     private SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-DD");
  
     //Stores current time and date
     Date date;
     Date time;
     String d = "";
     String t = "";           
  
     d= dateFormat.parse(date);
     t= timeFormat.parse(time);
  
     events.add(d, t);
  
     //Print out newly formatted date and time when loaded from mysql
     System.out.println(events.get(0).printDate());
     System.out.println(events.get(0).printTime());
  }
  </code></pre>
  
  <p>Events class</p>
  
  <pre><code>public class Event {    
     private String date;
     private String time;
  
     public Event(String d, String t) {
        date = d;
        time = t;
     }
  
     public String printDate() {
         SimpleDateFormat format = new SimpleDateFormat("DD/MM/YYYY");
         String newDate = format.format(date);
         return newDate;
     }
  
     public String printTime() {
         SimpleDateFormat format = new SimpleDateFormat("HH:mm");
         String newTime = format.format(time);
         return newTime;
     }
  }
  </code></pre>