473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

millisecond time conversion

3
Can anyone help me with creating this code in Java? PLEASE! Thanks in advance!

Ask the user for the number of milliseconds, validate that it's not negative, and
display the result, then ask if the user wants to convert another number
(you may use a confirmation dialog, or you may allow input of 1 for yes
and 2 for no). Keep converting milliseconds until the user chooses no.

Example: (5500) should return 0:00:05 and convertMillis(100000) should return 0:01:40.

except your result MUST be formatted so that minutes and seconds are always two digits
Apr 10 '07 #1
6 4829
hirak1984
316 100+
Do you want a complete code for this?
unfortunately we dont supply that.
If you want help,post the code you have tried.We will try to help.
Good Luck.
Can anyone help me with creating this code in Java? PLEASE! Thanks in advance!

Ask the user for the number of milliseconds, validate that it's not negative, and
display the result, then ask if the user wants to convert another number
(you may use a confirmation dialog, or you may allow input of 1 for yes
and 2 for no). Keep converting milliseconds until the user chooses no.

Example: (5500) should return 0:00:05 and convertMillis(100000) should return 0:01:40.

except your result MUST be formatted so that minutes and seconds are always two digits
Apr 10 '07 #2
Like hirak said we dont support full codes, you have to try and we will try to direct you in the right way.

Also this sounds like an assignment to me.

BSCode266
Apr 10 '07 #3
RedSon
5,000 Expert 4TB
Using a good, clear thread title is important. The reasons for this are:

* We want this site to grow, many of our new members find the site using a search engine, by using a good thread title you will help us grow the site by helping us get better search engine rankings.
* Using a good title will benefit you too because other members of the forum will be less likely to skip over your thread and it allows the experts to quickly scan through the forum for questions they know the answer to.
* If the threads are well titled it allows other users to easily see if there have been any threads that could be relevant to their own current problem.
* It is in everybody's best interests to post properly titled threads as the more time the moderators have to spend on managing titles the less time they have available to give answers to the questions posed.
Apr 10 '07 #4
Kuriii
3
Sorry guys.

This is what I have so far. I can't figure out how the input can be converted.

Thanks for your help in advance!

Expand|Select|Wrap|Line Numbers
  1.  
  2. import javax.swing.JOptionPane;
  3.     public class extraCredit {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.  
  8.  
  9.     int choice;    
  10.     do {
  11.       choice = Integer.parseInt(JOptionPane.showInputDialog(null, "Do you want to enter the milliseconds now?\n   1. Yes\n     2.  No"));
  12.  
  13.       switch (choice) {
  14.           case 1:
  15.  
  16.             int milli;
  17.         do {
  18.         milli = Integer.parseInt (JOptionPane.showInputDialog("Enter the number of milliseconds (Must be positive"));    
  19.             } 
  20.         while (milli < 0);
  21.  
  22.       break;
  23.  
  24.                             }
  25.             }
  26.     while (choice != 2);
  27.  
  28.  
  29.  
  30.         }
  31. }
Apr 10 '07 #5
hirak1984
316 100+
Well you need not be sorry for whatever...
By the way are you facing problem in converting the string input into integer(the Integer.parseInt() stuff) or converting the input into millisecond?
please make this clear and preferrably post the errors you are getting.
Sorry guys.

This is what I have so far. I can't figure out how the input can be converted.

Thanks for your help in advance!

Expand|Select|Wrap|Line Numbers
  1.  
  2. import javax.swing.JOptionPane;
  3.     public class extraCredit {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.  
  8.  
  9.     int choice;    
  10.     do {
  11.       choice = Integer.parseInt(JOptionPane.showInputDialog(null, "Do you want to enter the milliseconds now?\n   1. Yes\n     2.  No"));
  12.  
  13.       switch (choice) {
  14.           case 1:
  15.  
  16.             int milli;
  17.         do {
  18.         milli = Integer.parseInt (JOptionPane.showInputDialog("Enter the number of milliseconds (Must be positive"));    
  19.             } 
  20.         while (milli < 0);
  21.  
  22.       break;
  23.  
  24.                             }
  25.             }
  26.     while (choice != 2);
  27.  
  28.  
  29.  
  30.         }
  31. }
Apr 11 '07 #6
Kuriii
3
Hey

Thanks for your help. I figured it out. I needed help with the conversion from seconds to milliseconds so I just created a formula. 1 second to 1000 milli seconds. It was pretty simple after I figured it out. Thanks for your help though:)
Apr 15 '07 #7

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

Similar topics

8
by: szymex | last post by:
How can I get current time in milliseconds in ASP?
1
by: sgh | last post by:
Why doesn't this date time pattern support milliseconds? That makes it hard for me to map my date, time, and dateTime XML schema types to System.DateTime values without losing millisecond...
11
by: Yeounkun, Oh | last post by:
Hello. Sleep (x) function make a process sleep during x seconds. but, how to sleep during milliseconds... Pls. help me. Thank you. Regards.
3
by: Stu | last post by:
Hi, How can you get the time accurate to the millisecond? Thanks in advance, Stu
3
by: Jason S | last post by:
is there any way to use templates to bind integer/floating point constants to a template for compile-time use? e.g. template <double conversion> class meters { const factor = conversion;
4
by: Manikandan | last post by:
Hi, I'm inserting a datetime values into sql server 2000 from c# SQL server table details Table name:date_test columnname datatype No int date_t DateTime ...
5
by: Grey Alien | last post by:
I need to convert timestamps that are given as the number of seconds that have elapsed since midnight UTC of January 1, 1970, (not counting leap seconds). It seems all of the std C functions...
5
by: Hunter | last post by:
Hi all, I know it may sound like dump newbie question (which is very much true, as I am a newbie, not even a real programmer), but I need to implement a calendar time clock with a millisecond...
1
by: maul581 | last post by:
I know the delay( ) function of Turbo C and used it in my project. By this function we can give intermediate delay in execution from 1 millisecond to 9999 millisecond. My main question is "Is it...
0
by: maolimix | last post by:
Hi to all, I have a trouble with datetime...now I explain.. I must to store to a C# variable the values from a "Datetime column" of Sql Server 2005. I tried 3 methods ...in the first two I never...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.