472,337 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,337 software developers and data experts.

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 3100
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

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

Similar topics

6
by: Able | last post by:
Dear friends I need to format seconds as hh:mm:ss. I see a lot of coding transforming seconds to hh:mm:ss. Somebody know a short way? Regards...
4
by: Rich | last post by:
Now.ToShortTimeString returns 9:13 PM. I would like to get this in miliatry time with seconds included 21:13:45 (or something like that -...
14
by: Michael Barrido | last post by:
I have this for example: Dim iSeconds as int32 = 3600 '3600 seconds is one hour How do i convert it to "01:00:00" ? Please help. Thanks...
1
by: Jason Chan | last post by:
DateTime mydate = new DateTime(2006,1,1,0,0,0); string testStr = mydate.ToString("hh:mm:ss"); //return 12:00:00 mydate = new...
5
by: kpp9c | last post by:
Hi, I was looking at python & datetime and hoping that it would already have a method/func to translate time formats. I need to translate...
5
nirmalsingh
by: nirmalsingh | last post by:
i am getting date format in string as 30-11-2006 05:59:44 PM . i want to convert in the format of yyyy-mm-dd hh:mm:ss to sore it in mysql database....
4
sunbin
by: sunbin | last post by:
hi, How can i get the FLV file or any type of video file's duration in HH:MM:SS or HH:MM:SS:FF format from milliosecond ? I already got duration...
1
by: unknown66 | last post by:
hello, I have a time value in unix time that I would like to convert into a time format of hh:mm:ss:ms. For example, I have this number,...
1
seshu
by: seshu | last post by:
Hi every body to morning my cousine has show his application and also his live db in that to sav the length of all the voice files he has saved in...
1
seshu
by: seshu | last post by:
Hi every body to morning my cousine has show his application and also his live db in that to sav the length of all the voice files he has saved in...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.