Here you can find the source of toTimeString(final Calendar calendar)
Parameter | Description |
---|---|
calendar | a parameter |
public static String toTimeString(final Calendar calendar)
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.util.Calendar; public class Main { /*********************************************************************************************** * Show the Time value of a Calendar as a String. * This is putting right more problems with Java Dates... */*from w w w. j a v a 2s . c o m*/ * @param calendar * * @return String */ public static String toTimeString(final Calendar calendar) { String strHour; String strMinute; String strSecond; strHour = ""; strMinute = ""; strSecond = ""; if (calendar != null) { if (calendar.get(Calendar.HOUR_OF_DAY) < 10) { strHour = "0" + calendar.get(Calendar.HOUR_OF_DAY); } else { strHour = Integer.toString(calendar .get(Calendar.HOUR_OF_DAY)); } if (calendar.get(Calendar.MINUTE) < 10) { strMinute = "0" + calendar.get(Calendar.MINUTE); } else { strMinute = Integer.toString(calendar.get(Calendar.MINUTE)); } if (calendar.get(Calendar.SECOND) < 10) { strSecond = "0" + calendar.get(Calendar.SECOND); } else { strSecond = Integer.toString(calendar.get(Calendar.SECOND)); } } return (strHour + ":" + strMinute + ":" + strSecond); } }