Board index » jbuilder » first weekday of month

first weekday of month


2004-08-27 08:20:20 AM
jbuilder3
this month starts on a sunday. How can i get that with a
GregorianCalendar class?
I have made several attempts and i'm apparently not grasping something.
Thanks.
 
 

Re:first weekday of month

I think something like that should work:
Calendar c=GregorianCalendar.getInstance();
c.set(Calendar.DAY_OF_MONTH, 1);
System.out.println("Date: "+c.getTime());
System.out.println("First day is "+c.get(Calendar.DAY_OF_WEEK));
- Alexey.
Chris M wrote:
Quote
this month starts on a sunday. How can i get that with a
GregorianCalendar class?

I have made several attempts and i'm apparently not grasping something.

Thanks.
 

Re:first weekday of month

Ok thanks, why does that work and this returns 4.
Calendar c = new GregorianCalendar(2004,8,1);
iDayOfWeek = c.get(Calendar.DAY_OF_WEEK);
Alexey N. Solofnenko wrote:
Quote
I think something like that should work:

Calendar c=GregorianCalendar.getInstance();
c.set(Calendar.DAY_OF_MONTH, 1);
System.out.println("Date: "+c.getTime());
System.out.println("First day is "+c.get(Calendar.DAY_OF_WEEK));


- Alexey.

Chris M wrote:

>this month starts on a sunday. How can i get that with a
>GregorianCalendar class?
>
>I have made several attempts and i'm apparently not grasping something.
>
>Thanks.
 

{smallsort}

Re:first weekday of month

Chris M wrote:
Quote
Ok thanks, why does that work and this returns 4.

Calendar c = new GregorianCalendar(2004,8,1);
iDayOfWeek = c.get(Calendar.DAY_OF_WEEK);
Because months are numbered 0 to 11, so you're getting the day of the
week of the first day of September.
--
Gillmer J. Derge [TeamB]
 

Re:first weekday of month

Gillmer J. Derge [TeamB] wrote:
Quote
Chris M wrote:

>Ok thanks, why does that work and this returns 4.
>
>Calendar c = new GregorianCalendar(2004,8,1);
>iDayOfWeek = c.get(Calendar.DAY_OF_WEEK);


Because months are numbered 0 to 11, so you're getting the day of the
week of the first day of September.

Why thank you for breaking my paradigm that months must start with 1. :)
 

Re:first weekday of month

Chris M wrote:
Quote
Gillmer J. Derge [TeamB] wrote:

>
>Because months are numbered 0 to 11, so you're getting the day of the
>week of the first day of September.
>
Why thank you for breaking my paradigm that months must start with 1. :)
This is one of the more stupid hold-overs from the C language roots of
the Java developers. (But that's just MHO)
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html
 

Re:first weekday of month

Lori M Olson [TeamB] wrote:
Quote
This is one of the more stupid hold-overs from the C language roots of
the Java developers. (But that's just MHO)
Personally, I'd agree, but in fairness to Sun, I must also counter that
you're *supposed* to use the declared constants like Calendar.SUNDAY,
etc., for the days of the week, and Calendar.JANUARY, etc., for the months.