| | |
Calendar question
![]() |
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 |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






