| | |
Calendar question
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Java Syntax (Toggle Plain Text)
Calendar a = new Calendar(); a.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); Date b = Calendar.getTime();
As an example. There's a bit more to it, depending on exactly what you want to do, but that's a start (and more than a start).
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Mar 2006
Posts: 131
Reputation:
Solved Threads: 0
Thanks, it worked perfectly.
I have another question though: Given some date, how do I find out what the date for the first day of the week is? For instance,
When I do this, the first day of the week is set to whatever todaysDate is, which isn't what I want.
I have another question though: Given some date, how do I find out what the date for the first day of the week is? For instance,
Java Syntax (Toggle Plain Text)
GregorianCalendar cal = new GregorianCalendar(thisYear, thisMonth, todaysDate); cal.set(GregorianCalendar.DAY_OF_WEEK, i); int tempDate = cal.get(GregorianCalendar.DAY_OF_MONTH);
When I do this, the first day of the week is set to whatever todaysDate is, which isn't what I want.
Look at the add method of Calendar (hint, you can give it negative numbers). Cycle backwards and use get(Calendar.DAY_OF_WEEK) and compare it to the GregorianCalendar method getFirstDayOfWeek().
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Mar 2006
Posts: 131
Reputation:
Solved Threads: 0
All right I managed to get it. Thanks a bunch.
I'm still a little unclear about some of the fields in Calendar/GregorianCalendar though. I had to find out the hard day that decrementing DAY_OF_MONTH will also affect DAY_OF_WEEK. Am I reading the API wrong? b/c I was under the impression that they were distict fields with DAY_OF_MONTH giving you the date and DAY_OF_WEEK giving you UMTWThFS.
I'm still a little unclear about some of the fields in Calendar/GregorianCalendar though. I had to find out the hard day that decrementing DAY_OF_MONTH will also affect DAY_OF_WEEK. Am I reading the API wrong? b/c I was under the impression that they were distict fields with DAY_OF_MONTH giving you the date and DAY_OF_WEEK giving you UMTWThFS.
No. If you go backwards a day, you go backwards a day. It's a Calendar. Just like the one you have on the wall.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- Outlook 2003 Free/Busy question (Windows Software)
- quick question (C++)
- Calendar for programming one in c++ (C++)
- Inserted Calendar causing problems w/ Page (HTML and CSS)
- Retrieving dates from a dataset (Month Calendar) (Community Introductions)
- Use Calendar in GUI (Python)
- I change my account (ASP.NET)
- mock test question, can anyone help (C)
Other Threads in the Java Forum
- Previous Thread: Java using BlueJ- GUI (Graphic User Interface)
- Next Thread: Problem in creating a jar file
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth businessintelligence chat class classes client code component database desktop draw ebook eclipse encode equation error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer intersect j2me java javaexcel javaprojects jmf jni jpanel julia linked linux list loop mac main map method methods mobile netbeans newbie number object online open-source oracle parameter print problem program programming project properties recursion reference replaysolutions rotatetext scanner score screen scrollbar server set size sms socket sort sql string superclass swing template test threads time tree windows xstream






