title: How do I format a java.sql.Timestamp as (hh:mm AM/PM)
body: <p>I have a java.sql.Timestamp and I would like to cut off the date and show it in 12 hour fashion, eg (18:42 as 6:42PM)</p>
  
  <p>I tried: </p>
  
  <pre><code>public static String formatTimestampAsTwelveHour(java.sql.Timestamp stamp){
  
          String stampString = stamp.toString();
          String hms  = stampString.split(" ")[1];
          String[] hmsArray = hms.split(":");
          int hours = Integer.parseInt(hmsArray[0]);
          int minutes = Integer.parseInt(hmsArray[1]);
          int seconds = Integer.parseInt(hmsArray[2]);//just in case someone wants seconds
  
          String suffix = "";
          if (hours &gt; 12){
              hours = hours -12;
              suffix = "PM";
          }else if (hours == 12){
              suffix = "PM";
          }else{
              suffix = "AM";
          }
          String lessThanTen = "";
          if (minutes&lt;10){
              lessThanTen = "0";
          }
          return String.format("%i:%s%i %s", hours, lessThanTen,minutes, suffix);
  
  }
  </code></pre>
  
  <p>I get (Exception in thread "Thread-14" java.lang.NumberFormatException: For input string: "06.0") but I never give it a decimal number.</p>