aspose file tools*
The moose likes Beginning Java and the fly likes Cannot Convert String to Int.  Clock question. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cannot Convert String to Int.  Clock question." Watch "Cannot Convert String to Int.  Clock question." New topic
Author

Cannot Convert String to Int. Clock question.

Christopher Schneider
Greenhorn

Joined: Aug 10, 2011
Posts: 3
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):

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18564
    
    8

Use a DecimalFormat object if you want to format a number in some specific way.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38756
    
  23
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.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot Convert String to Int. Clock question.