469,950 Members | 2,341 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

how to set the time in hh:mm:ss format

Here is my code...

class TimeConverter
{
public static void main(String ar[])
{
int sec=3650;
int min=0;
int hour=0;
while(sec>=60)
{
sec=sec-60;
min++;
while(min>=60)
{
min=min-60;
hour++;
}

}
System.out.println("Time in hours--"+hour+":"+min+":"+sec);


}
}

output:1:0:50....

i need in a format of 01:00:50(hh:mm:ss)
plese help me regarding this Friends....
May 1 '07 #1
1 2943
JosAH
11,448 Expert 8TB
Here is my code...

class TimeConverter
{
public static void main(String ar[])
{
int sec=3650;
int min=0;
int hour=0;
while(sec>=60)
{
sec=sec-60;
min++;
while(min>=60)
{
min=min-60;
hour++;
}

}
System.out.println("Time in hours--"+hour+":"+min+":"+sec);


}
}

output:1:0:50....

i need in a format of 01:00:50(hh:mm:ss)
plese help me regarding this Friends....
For one thing: you don't need those loops:
Expand|Select|Wrap|Line Numbers
  1. min+= sec/60;
  2. hour+= min/60;
  3. min%= 60;
  4. sec%= 60;
... and have a look at the printf() method for the System.out PrintStream class.

kind regards,

Jos
May 1 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Able | last post: by
5 posts views Thread by kpp9c | last post: by
sunbin
4 posts views Thread by sunbin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.