Hello folks, back again. The book I'm reading had me create a simple clock program, and it works fine.
However, when it displays the time, if the minutes are below 10, it doesn't show a zero in front, and it doesn't look right. e.g. if it's 10:09, it shows up at 10:9 in the window. It's not a big deal, and I'm still moving on to the next chapter of the book, but I'd like to know how to do this anyway. Here's the code (irrelevant information excluded):
Or go through the java.util.Formatter class to read about the % tags. Look through those after %T. They will probably allow you to dispense with the + 1 for month. They will take the Calendar object, so you don't need to separate it into separate fields.
Paul Clapham wrote:Use a DecimalFormat object if you want to format a number in some specific way.
Or DateFormat (usually SimpleDateFormat) to format a Date object directly. That can take care of adding the month names as well; a Locale can be used to format them in a specific language. The Calendar can then be dropped in favour of a new Date() object.