Intern
asked on
Simple Calendar question. Formatting output.
I am creating a log for files that are emailed through my program. The only problem is that when the following statement executes it shows like this:
9:1:36
I want it to show
9:01:36
Calendar today = Calendar.getInstance();
System.out.println(today.g et(Calenda r.HOUR)+": "+today.ge t(Calendar .MINUTE)+" :"+today.g et(Calenda r.SECOND)) ;
The seconds also will show only one character when the seconds are between 0 and 9. Thanks for any help.
9:1:36
I want it to show
9:01:36
Calendar today = Calendar.getInstance();
System.out.println(today.g
The seconds also will show only one character when the seconds are between 0 and 9. Thanks for any help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
s = s.substring(0, s.indexOf("@"));
If you want *all* fields to have two digits:
SimpeDateFormat sdf = new SimpleDateFormat("hh:mm:ss ");
or in 24hr clock:
SimpeDateFormat sdf = new SimpleDateFormat("HH:mm:ss ");
SimpeDateFormat sdf = new SimpleDateFormat("hh:mm:ss
or in 24hr clock:
SimpeDateFormat sdf = new SimpleDateFormat("HH:mm:ss
ASKER
Thank you very much for helping a Java newbie so quickly.
:-)
ASKER