A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Java in General
Author
Differnce between time.
Neeba Rebbaca
Ranch Hand
Joined: Oct 21, 2008
Posts: 116
posted
Sep 10, 2010 04:01:12
0
I want to find the differnce between two time which is in 12 hrs format.
String fromtime = 12.00.00 AM String toTime = 9.00.00 AM SimpleDateFormat sdf_time = new SimpleDateFormat("HH:mm:ss a"); Date frm_time = sdf_time.parse(fromtime); Date to_time = sdf_time.parse(toTime); Calendar fromtime_calendar = Calendar.getInstance(); Calendar totime_calendar = Calendar.getInstance(); fromtime_calendar.setTime(frm_time); totime_calendar.setTime(to_time); long milis1 = fromtime_calendar.getTimeInMillis(); long milis2 = totime_calendar.getTimeInMillis(); long diff = milis2 - milis1; long diffHours = diff / (60 * 60 * 1000); //since i want the time differnce in hours
But instead of getting 9 hrs differnce, i'm getting only 3 hrs differnce.
Where i'm going wrong?
Raymond Tong
Ranch Hand
Joined: Aug 15, 2010
Posts: 156
I like...
posted
Sep 10, 2010 04:34:13
0
http://download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html
Check on the letter for Hour.
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
I like...
posted
Sep 10, 2010 04:40:24
0
Just for the sake of providing docs that aren't really old:
http://download-llnw.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
I like...
posted
Sep 10, 2010 04:46:12
0
And please post actual code--those dates aren't even parseable by your own code.
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: Differnce between time.
Similar Threads
10000 milliseconds showing as 01:00:10.000 - why ?
find time differnce between to calender
Need to find diff between two dates : - 60 days
Difference Between two dates
Time format in Java
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter