| | |
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 |
3d 6 @param affinetransform android api applet application arc array arrays automation binary bluetooth bold byte c++ chat class classes click client code compare component coordinates database detection doctype draw eclipse educational error event exception file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework html ide ideas image ingres input integer internet intersect j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list loop map method methods mobile netbeans newbie nextline oracle pong print problem program programming project recursion recursive rim scanner screen sell server set size sms sort sql string swing terminal threads time tree user web websites windows






