Here you can find the source of getHour(boolean military)
public static String getHour(boolean military)
//package com.java2s; /******************************************************************************* * Copyright (c) 2005-2012 Synopsys, Incorporated * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*www .j a va 2s.c o m*/ * Synopsys, Inc - Initial implementation *******************************************************************************/ import java.util.Calendar; public class Main { private static Calendar mCalendar = null; /** * Returns the current hour as a string. Option specifies whether to use military time. Range is from 1-24. * @return the current hour. */ public static String getHour(boolean military) { if (mCalendar == null) Init(); String retVal = null; int val = mCalendar.get(Calendar.HOUR_OF_DAY); if (military) { if (val < 10) retVal = "0" + val; else retVal = val + ""; } else { if (val > 12) val -= 12; if (val < 10) retVal = "0" + val; else retVal = val + ""; } return retVal; } /** * This method creates a new Calendar object */ public static void Init() { mCalendar = Calendar.getInstance(); } }