• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get the Days of a specific month  RSS feed

 
Mahendran Aiyappan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

In myproject I need a function which will be having one argument as input which is a month.

This function should return a collection which should have all the days present in that month.

Can anybody help me.
Thanks for your comments.

Mahendran
 
Ashok Kumar
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell us what have you tried then we can help you.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This function is impossible with only one parameter. What do you return if the month is February?
[ March 07, 2007: Message edited by: Paul Sturrock ]
 
Mahendran Aiyappan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

Thanks for your reply,

Why what will happen if it is February???

I don't get any idea of whether I have to use Georgaein Calender class.

Any ideas.

Mahendran
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your method looks like this:

and you have no other parameter to define what year it is, then if you pass in an integer representing February you can have two outputs; a List that has 28 elements or 29 elements. Which do you use?
 
Mahendran Aiyappan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok Paul,


I understood the problem,

now assume we have two parameters (month, year).

Now how to get the days of that month.

Mahendran
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the Calendar interface (and the Gregorian Calendar implementation). It contains a method called getActualMaximum() that returns the maximim value a field can be. That should get you started.
 
Mahendran Aiyappan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul,

I got the answer for that Question.

But the second question is

How to get the Day (Sun,Mon etc) if i pass a Date as a parameter

Mahendran
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the Calendar class again, specifically the get field. And look at the available constants defined in the Calendar class. There are MONDAY, TUESDAY etc. constants you can use. The Calendar won't in itself return a label for the day - since this is a lot of overhead (it would need to internalionalize the response). But you can write a quick bit of conditional code to return the label based on the value the Calendar provides.
 
Mahendran Aiyappan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's alright Paul,

I got the answer from the following URL

web page

Mahendran
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you could go down the route demonstrated in that page (its a useful read regardless, since it highlights some of the computation that needs done to work out dates). However, why do that when Java gives you the GregorianCalendar class that encapsulates all this functionality?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!