Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: number of the days (-) days gone past

  1. #1
    sh4rif is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default number of the days (-) days gone past

    Hello Folks

    On my form I want to display the number of day.. i.e.
    Jan 1 is day 1
    jan 2 is day 2
    Feb 1 is day 32 and december 31 is day 365 or 366 depending on leap year or not

    i have used all kind of techniques such as date1 - date2 etc...
    but nothing seems to work for me cant get the logic right may be.. what i want is count and add the number of the months that has gone past plus the number days of the running month i. 22nd may 2012 is day number (31(jan)+29(feb)+31(mar)+30(apr)+22(currentdate)) = 145 and they will keep adding plus one every time a day go past... thanks

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: number of the days (-) days gone past

    Read the API for java.util.Calendar

    Or if this is homework and you have to reinvent the wheel, post your best efforts and indicate where exactly you still have a problem.

    db
    sh4rif likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: number of the days (-) days gone past

    So what code have you got so far, since you say you have "used all kind of techniques"?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    sh4rif is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: number of the days (-) days gone past

    its not a homework its real work which i am doin free for someone....

    Java Code:
    //constructor
    public DateDifference() {
    		Calendar cal1 = new GregorianCalendar();
    		 Calendar cal2 = new GregorianCalendar();
    
    		 cal1.getTime();
    		 //System.out.println(cal1);
    		 cal2.set(2012, 01, 01);
    		 //System.out.println(cal2);
    		 //daysBetween(cal1.getTime(), cal2.getTime());
    		 System.out.println("Days= "+ this.daysBetween(cal1.getTime(),cal2.getTime()));
    	}
    
    public int daysBetween(java.util.Date date, java.util.Date date2){
    		 return (int)( (date2.getTime() - date.getTime()) / (1000 * 60 * 60 * 24));
    }
    there are few more which doesnt make sence but i cant manage to get the logic right...

    thanks

  5. #5
    sh4rif is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: number of the days (-) days gone past

    Thankyou very much DarrylBurke i got my answer thanks very much

Similar Threads

  1. Help, I have been working on this for days
    By ajimda in forum New To Java
    Replies: 2
    Last Post: 10-28-2011, 04:46 PM
  2. Best way to find number of days between 2 dates??
    By alinaqvi90 in forum Advanced Java
    Replies: 18
    Last Post: 11-22-2010, 08:49 AM
  3. Calendar days mixed up..
    By tomblue84 in forum AWT / Swing
    Replies: 0
    Last Post: 03-17-2010, 05:08 PM
  4. No fo days between two dates
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-28-2008, 09:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •