?
Solved

Simple Calendar question.  Formatting output.

Posted on 2005-04-13
6
Medium Priority
?
253 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:Intern
  • 4
  • 2
6 Comments
 
LVL 1

Author Comment

by:Intern
ID: 13774094
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"
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 13774098
SimpeDateFormat sdf = new SimpleDateFormat("h:mm:ss");
System.out.println(sdf.format(today.getTime()));
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13774122
s = s.substring(0, s.indexOf("@"));
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Expert Comment

by:CEHJ
ID: 13774174
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");
0
 
LVL 1

Author Comment

by:Intern
ID: 13774224
Thank you very much for helping a Java newbie so quickly.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13774706
:-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month16 days, 5 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question