title: get(GregorianCalendar.HOUR) returning 12 hr time. Java
body: <p>I searched on the forum and others had the same issue however the solutions did not work for me. I have two problems. I can't get it to display am_pm correctly and GregorianCalendar.HOUR is returning a 24 hour value instead of 12.</p>
  
  <p>here is my code:</p>
  
  <pre><code>package lab11;
  
  import java.util.*;
  public class Lab11 {
  
  
   public static void main(String[] args) {
  
      Calendar time = new GregorianCalendar(); //create new gregorian calendar object
      int month = time.get(GregorianCalendar.MONTH); // create variables
      int year = time.get(GregorianCalendar.YEAR);
      int DOM = time.get(GregorianCalendar.DAY_OF_MONTH);
      int DOW = time.get(GregorianCalendar.DAY_OF_WEEK);
      int hour = time.get(GregorianCalendar.HOUR);
      int minute = time.get(GregorianCalendar.MINUTE);
      int second = time.get(GregorianCalendar.SECOND);
      long setMill = 1234567898765L;
      System.out.println(hour);
      String dayofw = "";
      int am_pm = time.get(GregorianCalendar.AM_PM);
      switch (am_pm) {
          case  Calendar.AM:
              System.out.println("AM");
              break;
          default:
              System.out.println("PM");
              break;
         }
      if (hour == 0){
          hour = 12;
      }
  
      switch(DOW){ //switch statement to translate numeric value of DOW to string value
          case 1: dayofw = "Sunday";
              break;
          case 2: dayofw = "Monday";
              break;
          case 3: dayofw = "Tuesday";
              break;
          case 4: dayofw = "Wednesday";
              break;
          case 5: dayofw = "Thursday";
              break;
          case 6: dayofw = "Friday";
              break;
          case 7: dayofw = "Saturday";
              break;
  
      }
      if (minute &gt;= 0 &amp;&amp; minute &lt;= 9){ //add an extra 0 infront of minutes for formatting
      System.out.println("Today's date is " +  (month + 1) + "/" + (DOM) + "/" + year);
      System.out.println("Today's day is " + dayofw + ", and the time is " + hour + ":0" + minute + (am_pm == Calendar.AM ? "am" : "pm") + " and " + second + " seconds" );
      System.out.println("Today's date in MILLISECONDS = " + time.getTimeInMillis() + "\n");
      }
      else{ //if minutes are 10 or above don't add a 0 infront of minutes
      System.out.println("Today's date is " +  (month + 1) + "/" + (DOM) + "/" + year);
      System.out.println("Today's day is " + dayofw + ", and the time is " + hour + ":" + minute + (am_pm == Calendar.AM ? "am" : "pm")+ " and " + second + " seconds" );
      System.out.println("Today's date in MILLISECONDS = " + time.getTimeInMillis() + "\n");   
      }
      GregorianCalendar setTime = new GregorianCalendar(); //create object for the set date
      setTime.setTimeInMillis(setMill); //set time in milliseconds to the set value
      month = setTime.get(GregorianCalendar.MONTH); //update values for variables
      year = setTime.get(GregorianCalendar.YEAR);
      DOM = setTime.get(GregorianCalendar.DAY_OF_MONTH);
      int DOW2 = setTime.get(GregorianCalendar.DAY_OF_WEEK);
      switch(DOW2){
          case 1: dayofw = "Sunday";
              break;
          case 2: dayofw = "Monday";
              break;
          case 3: dayofw = "Tuesday";
              break;
          case 4: dayofw = "Wednesday";
              break;
          case 5: dayofw = "Thursday";
              break;
          case 6: dayofw = "Friday";
              break;
          case 7: dayofw = "Saturday";
              break;
  
      }
  
      hour = setTime.get(GregorianCalendar.HOUR);
      minute = setTime.get(GregorianCalendar.MINUTE);
      second = setTime.get(GregorianCalendar.SECOND);
      int am_pm2 = time.get(GregorianCalendar.AM_PM);
  
  
       if (minute &gt;= 0 &amp;&amp; minute &lt;= 9){ //add an extra 0 infront of minutes for formatting
      System.out.println("The set date is " + (month) + "/" + (DOM) + "/" + year);
      System.out.println("The set day is " + dayofw + ", and the time is " + hour + ":0" + minute + (am_pm2 == Calendar.AM ? "am" : "pm") + " and " + second + " seconds" );
      System.out.println("The set date in MILLISECONDS = " + setMill);
      }
      else{ //if minutes are 10 or above don't add a 0 infront of minutes
      System.out.println("The set date is " + (month) + "/" + (DOM) + "/" + year);
      System.out.println("The set day is " + dayofw + ", and the time is " + hour + ":" + minute + (am_pm2 == Calendar.AM ? "am" : "pm") + " and " + second + " seconds" );
      System.out.println("The set date in MILLISECONDS = " + setMill);  
      }
  
      }
  
  }
  </code></pre>