Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Differnce between time.
Neeba Rebbaca
Ranch Hand
Posts: 162
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 258
2
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
http://download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html
Check on the letter for Hour.
David Newton
Author
Posts: 12617
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 12617
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
And please post actual code--those dates aren't even parseable by your own code.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
10000 milliseconds showing as 01:00:10.000 - why ?
Difference Between two dates
find time differnce between to calender
Time format in Java
Need to find diff between two dates : - 60 days
More...