The Artima Developer Community
Sponsored Link

Java Answers Forum
Creating a Calendar

1 reply on 1 page. Most recent reply: Apr 8, 2003 9:54 AM by Senthoorkumaran Punniamoorthy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Mimi

Posts: 1
Nickname: mika
Registered: Apr, 2003

Creating a Calendar Posted: Apr 8, 2003 9:09 AM
Reply to this message Reply
Advertisement
This is for a homework assignment. I cannot figure out how to create a method that will return a new CalendarDate object representing the day immediately following the calling CalendarDate. The previous method I created was:

public CalendarDate(int M, int D, int Y){

......
}

And I was able to type in 3 4 2003 and have it display as March 4, 2003. I need to be able to call a method that will change it to March 5, 2003. I also need to create a method that will allow me to put in any date and then ask what day is it 50 days from now. I really need help.


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Creating a Calendar Posted: Apr 8, 2003 9:54 AM
Reply to this message Reply
public String CalendarDate(int M, int D, int Y){

GregorianCalendar myCal = new GregorianCalendar(Y,M-1,D);
//Month is 0 based so January is 0
myCal.roll(GregorianCalendar.DAY_OF_MONTH,1);
return myCal.toString();
}

Go through this method and the API for java.util.GregorianCalendar and you should be able to do the rest. Here are some extracts from the API

System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
System.out.println("DATE: " + calendar.get(Calendar.DATE));
System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
System.out.println("DAY_OF_WEEK_IN_MONTH: "
+ calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));

Flat View: This topic has 1 reply on 1 page
Topic: Help needed for JTapi Application Previous Topic   Next Topic Topic: package

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use