Results 1 to 5 of 5
  1. #1
    tirwit is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default Gregorian calendar multiple dates

    Is it possible to create a GregorianCalendar object and set multiple dates in it? For creating intervals of time in it, and then associate it with a person.

    This is to be used to create a vacation calendar so multiple intervals.

    If you have any good idea or other approach to the problem, please share!:o

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,352
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by tirwit View Post
    Is it possible to create a GregorianCalendar object and set multiple dates in it? For creating intervals of time in it, and then associate it with a person.

    This is to be used to create a vacation calendar so multiple intervals.

    If you have any good idea or other approach to the problem, please share!:o
    No, a Calendar works on one moment in time only; that moment in time may change though; you can get/set it with the get/setTime() methods. If you want to manage more than one moment in time use the Date(s) returned by the getTime() method.

    kind regards,

    Jos

  3. #3
    tirwit is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    Ok, I wrote some code, but I'm having trouble with calculating work days between 2 days.

    This is it:
    Java Code:
    public static int daysBetween(GregorianCalendar startDate, GregorianCalendar endDate) {  
    	  GregorianCalendar date = (GregorianCalendar) startDate.clone();  
    	  int daysBetween = 0;  
    	  while (date.before(endDate)) {  
    		date.add(GregorianCalendar.DAY_OF_MONTH, 1);
    		
    		if(date.equals(GregorianCalendar.SATURDAY) || date.equals(GregorianCalendar.SUNDAY)){}
    		
    		else
    		daysBetween++;
    	  }  
    	  return daysBetween;  
    	}
    But GregorianCalendar.SATURDAY is of type int... How can I compare date to a GregorianCalendar object to see if it a saturday?
    Last edited by tirwit; 09-17-2010 at 02:48 PM.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,352
    Blog Entries
    7
    Rep Power
    20

    Default

    date.get(Calendar.DAY_OF_WEEK)? It's all in the API documentation you know ...

    kind regards,

    Jos

  5. #5
    tirwit is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    I tried that before but it was not working. I had imported only the GregorianCalendar, because I thought that since GregorianCalendar is a extension of Calendar, all the methods would be there as well. Turns out I was wrong. I imported the Calendar and now it's working! Thank you so much.

    PS: I was not slacking, I read the the API, but I have 3 days of Java, so I'm still learning to move around here (the "extend" stuff and such) :-) Thanks for your time showing me how to!

Similar Threads

  1. Gregorian Calendar
    By bindhuuk4 in forum New To Java
    Replies: 1
    Last Post: 08-07-2009, 12:00 PM
  2. Creating a Gregorian Calendar using a Date object gives date - 1
    By prachi_goliwadekar in forum New To Java
    Replies: 1
    Last Post: 05-08-2008, 08:32 PM
  3. Help with gregorian calendar
    By osval in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 11:21 PM
  4. Calendar with multiple languages
    By Marcus in forum Web Frameworks
    Replies: 1
    Last Post: 06-27-2007, 04:14 PM
  5. Gregorian calendar issue
    By orchid in forum New To Java
    Replies: 1
    Last Post: 05-16-2007, 06:51 PM

Tags for this Thread

Posting Permissions

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