example
i will enter
timein: 1:30
timeout: 5:00
how to know their time difference?in timeformat
or how to accept a timeformat input from the user
example
i will enter
timein: 1:30
timeout: 5:00
how to know their time difference?in timeformat
or how to accept a timeformat input from the user
You can use the SimpleDateFormat class to parse a time in format "hh:mm" and convert that to a Date object. You can convert two date objects to millisecs and subtract one from the other to get the time difference. You can finally use that to create a new Date object for the difference, and format it with the same SimpleDateFormat
Details, as always, are in the API JavaDoc
how to get the time diff? i cant seem to figure it out.. example pls
You can use the getTime() method to convert your Data object to milliseconds. Do that for both dates and subtract one answer from the other. That gives you the diff in mSecs.
example code sir ..
This isn't a "we do your homework" service. You have to do the work, and we help you.
DaniWeb Member Rules include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/forums/faq.php?faq=daniweb_policies
http://www.daniweb.com/forums/announcement8-2.html
ok
String time1 = "1:00",time2="1:30";
DateFormat sdf = new SimpleDateFormat("H:mm");
Date date = sdf.parse(time1);
Date date1 = sdf.parse(time2);
long diff = date1.getTime() - date.getTime();
System.out.println((diff / (1000*60*60)));
That's a good start. Does it give you the result you wanted?
the result is 0
Yes it is. Difference is 30 mins, ie 30*60*1000 mSec. You display the difference in hours, not minutes, and in integer arithmetic this is truncated to 0 hours.
example
i will enter
timein: 1:30
timeout: 5:00how to know their time difference?in timeformat
or how to accept a timeformat input from the user
check out here, can use an external API or the one you're trying:http://stackoverflow.com/questions/6690929/convert-string-to-time-and-calculate-difference
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.