Article View: comp.lang.java.help
Article #74Re: HOW to get the intervall between 2 dates ???
From: elidan1
Date: Sun, 04 Jun 2000 00:00
Date: Sun, 04 Jun 2000 00:00
51 lines
2212 bytes
2212 bytes
In article <8hddtn$b51$1@news4.isdnet.net>, "Jerome" <nospam:jdeschars@yahoo.com> wrote: >HI > >i've got a pb ... >I want to get the interval between 2 dates ! > >Should i use java.util.Date or java.util.calendar ?? > >For example, if i have two dates: > Date date1=new Date(20/05/2000); > Date date2=new Date(12/06/2000); > >how can i get the number of days between these dates ??? (with the months of >31,30 or 28 days ;-)) ) > > > I'm sure there must be something fancier, but converting your dates to milliseconds, substracting them, dividing by the number of milliseconds in a day and converting back will work fine: . long date1Milli = date1.getTime(); long date2Milli = date2.getTime(); long difference = date2Milli-date1Milli; int daysBetween = (int)(difference/(1000*60*60*24)); . BTW the Date constructor you are using is deprecated. Check the docs. >Thanks > >Jerome > >PS: sorry for my english, im French > > > > > > > elidan1 for mail null IS null nullelidan1@nullzahav.net.il * Sent from RemarQ http://www.remarq.com The Internet's Discussion Network * The fastest and easiest way to search and participate in Usenet - Free!
Technical Details
Message-ID:
<071b9ecc.e2a9d4c6@usw-ex0105-038.remarq.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<8hddtn$b51$1@news4.isdnet.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f6cb0,c1edb2e3df598165 X-Google-Attributes: gidf6cb0,public X-Google-Thread: 113ae9,c1edb2e3df598165 X-Google-Attributes: gid113ae9,public X-Google-Thread: f74b3,c1edb2e3df598165 X-Google-Attributes: gidf74b3,public From: elidan1 <elidan1NOelSPAM@zahav.net.il.invalid> Subject: Re: HOW to get the intervall between 2 dates ??? Date: 2000/06/04 Message-ID: <071b9ecc.e2a9d4c6@usw-ex0105-038.remarq.com> X-Deja-AN: 630882953 References: <8hddtn$b51$1@news4.isdnet.net> Bytes: 1221 X-Originating-Host: 213.8.253.116 X-Complaints-To: wrenabuse@remarq.com X-Trace: WReNphoon3 960122012 10.0.2.38 (Sun, 04 Jun 2000 05:33:32 PDT) Organization: http://www.remarq.com: The World's Usenet/Discussions Start Here NNTP-Posting-Date: Sun, 04 Jun 2000 05:33:32 PDT Newsgroups: comp.lang.java.help,borland.public.jbuilder.java.language,cn.bbs.comp.lang.java X-Wren-Trace: eH5bc3JrLGYtO2Z/fz9xJkx3b3N6bHBmfmY/dHsqNW8iNmYxIms4PiMuLA==