Link to home
Start Free TrialLog in
Avatar of Intern
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.get(Calendar.HOUR)+":"+today.get(Calendar.MINUTE)+":"+today.get(Calendar.SECOND));

The seconds also will show only one character when the seconds are between 0 and 9.  Thanks for any help.
Avatar of Intern
Intern

ASKER

Also one other simple thing.  I have a STRING variable that has the following in it "someone@domain.com"  I would like to print only the "someone" portion of the variable.  The variable will always contain "######@domain.com"
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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");
Avatar of Intern

ASKER

Thank you very much for helping a Java newbie so quickly.
:-)