Results 1 to 3 of 3
  1. #1
    osval is offline Member
    Join Date
    Jul 2007
    Posts
    26
    Rep Power
    0

    Default Help with gregorian calendar

    I'm trying to calculate how many days left in the year but it doesn't work

    this is my code:
    Java Code:
    public class Calculate
    {
    public static void main (String args[])
    {
    GregorianCalendar today = new GregorianCalendar();
    GregorianCalendar nyear = new GregorianCalendar(365,12,31);
    long daysleft= nyear .get(nyear .DAY_OF_YEAR) - today.get(today.DAY_OF_YEAR);
    
    
    System.out.println( daysleft);
    }
    
    }
    thanks

  2. #2
    bbq
    bbq is offline Senior Member
    Join Date
    Jun 2007
    Posts
    132
    Rep Power
    0

    Default

    maybe here is the answer
    Java J2EE Tutorials

  3. #3
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
    DateFormat df = new SimpleDateFormat("ddMMMyyyy");
    Calendar today = Calendar.getInstance();
    System.out.println("today = " + df.format(today.getTime()));
    Calendar endOfYear = Calendar.getInstance();
    endOfYear.set(2007, 11, 31);
    System.out.println("endOfYear = " + df.format(endOfYear.getTime()));
    int daysRemaining = endOfYear.get(Calendar.DAY_OF_YEAR) -
                            today.get(Calendar.DAY_OF_YEAR);
    System.out.println("days remaining = " + daysRemaining);
    GregorianCalendar start = new GregorianCalendar();
    GregorianCalendar end = new GregorianCalendar(2007, 11, 31);
    long daysLeft = end.get(Calendar.DAY_OF_YEAR) -
                  start.get(Calendar.DAY_OF_YEAR);
    System.out.println("daysLeft = " + daysLeft);

Similar Threads

  1. calendar
    By John in forum SWT / JFace
    Replies: 12
    Last Post: 08-07-2008, 10:54 PM
  2. How to use Calendar class
    By JavaBean in forum Java Tip
    Replies: 1
    Last Post: 06-26-2008, 03:09 PM
  3. Calendar.DATE
    By mew in forum New To Java
    Replies: 1
    Last Post: 01-04-2008, 07:51 PM
  4. Web calendar
    By Daniel in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 06-27-2007, 05:36 PM
  5. Gregorian calendar issue
    By orchid in forum New To Java
    Replies: 1
    Last Post: 05-16-2007, 06:51 PM

Posting Permissions

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