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
Win a copy of
Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams
this week in the
Agile and Other Processes
forum!
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
Devaka Cooray
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Jeanne Boyarsky
Tim Cooke
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Mikalai Zaikin
Carey Brown
Bartenders:
Forum:
Java in General
Difference between 2 date in day
amit sharma
Ranch Hand
Posts: 129
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I need to calculate difference between 2 date in number of days .for e.g.
say one date is 1-mar-2007 11:59PM and another is 2-mar-2007 0:1AM
the it should give 1
Thanks
Ibrahim AlShehri
Greenhorn
Posts: 12
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
i wrote this method and i hope you find it useful
public int daysDiff(Date d1, Date d2) { Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(d1); c2.setTime(d2); int days = 0; if(d1.before(d2)) { while(c1.getTime().before(c2.getTime())) { c1.add(Calendar.DATE,1); days++; } } else { while(c2.getTime().before(c1.getTime())) { c2.add(Calendar.DATE,1); days++; } } return days; }
[ March 02, 2007: Message edited by: Ibrahim AlShehri ]
SCJP 5.0 (87%)
And then the flying monkeys attacked. My only defense was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
oracle DATE
java
Problem or bug with the method getTime() from java.util.Date
difference between two dates
Regarding SCEA voucher
More...