| Author |
getting the current quarter
|
Bill Brasskey
Ranch Hand
Joined: Jun 01, 2004
Posts: 47
|
|
|
Is there any way to return the current quarter of the year in Java??
|
 |
Ta Ri Ki Sun
Ranch Hand
Joined: Mar 26, 2002
Posts: 442
|
|
You won't find a getCurrentQuarter(new Date()) method in Calendar if that's what you're looking for You can ofcourse write it, get the current month and check which quarter it falls into, hope that helps.
|
 |
Chengwei Lee
Ranch Hand
Joined: Apr 02, 2004
Posts: 884
|
|
To be very mean, I could ignore your post To be mean, I could reply saying yes. To harm you by spoon-feeding, I could give you the codes that you need. So, I thought I should just give you enough hints & guides to help you help yourself. Its much more exciting & fulfiling this way too. First of all, it really depends on your definition of a quarter, is it the financial year quarter, academic year, or just a normal calendar quarter. Assuming we're using the normal calendar quarter year, Jan-Mar would be the 1st, Apr-Jun the 2nd and so on... So if you know what is the current system month of the year, you could determine which quarter it falls in. I guess you won't have any problems coming up with this algorithm yourself. Hint #1: Take a look at java.util.GregorianCalendar; you can use this class to give you the current system month, and other stuffs. In short, read the API, you'll be rewarded for your hardwork. Hint #2: Use case switch to determine the quarter. Hint #3: In Java, a lot of stuffs start from 0 instead of 1. Sorry for being naggy & lengthy. And happy helping yourself!  [ July 06, 2004: Message edited by: Cheng Wei Lee ]
|
SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
|
 |
Dale DeMott
Ranch Hand
Joined: Nov 02, 2000
Posts: 514
|
|
Bill, There isn't an API that I know of that does this. You'll probably need to code it. I realize some people believe they are so much more above you and they need to show it by replying rudely to you. I don're know why they need to do this. This is a beginner forum. Its just too bad poeple need to be this way. It just shows poor manners and goes totally against the theme of Java Ranch. [ July 06, 2004: Message edited by: Dale DeMott ]
|
By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
|
 |
Tom Blough
Ranch Hand
Joined: Jul 31, 2003
Posts: 263
|
|
Subtract 1 from the current month, integer divide by 3, and then add 1 to get the current quarter. [ July 06, 2004: Message edited by: Tom Blough ]
|
Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
|
 |
Chengwei Lee
Ranch Hand
Joined: Apr 02, 2004
Posts: 884
|
|
I beg your pardon Dale. First of all, I've no intentions of being rude. Allow me to quote this, in case you didn't notice it:
Also, when responding to inquiries, please focus efforts on helping others to learn to figure out the solutions - not on just giving them the solutions. - Dirk
I don't think that I know more than Bill. I don't think my reply to him was rude. Believe me, there's much worse replies around here. Besides, if my posting goes against the theme of the forum, there's Dirk here who I think will not hesitate to reprimand me. Yes, we're all here to learn, the keyword is learn isn't it? Instead of telling him he has to code it himself, I gave him hints which he could follow and get it done. I believe he would feel a greater sense of achievement having coding the solution himself than simply just getting someone's codes. Let the rest of the ranchers judge for themselves. Let Bill judge if I was rude and my reply was useless (compared to just telling him to code it himself). I'm totally confused to your reply.
|
 |
Chengwei Lee
Ranch Hand
Joined: Apr 02, 2004
Posts: 884
|
|
Originally posted by Tom Blough: Subtract 1 from the current month, integer divide by 3, and then add 1 to get the current quarter.
You're brilliant!
|
 |
Tom Blough
Ranch Hand
Joined: Jul 31, 2003
Posts: 263
|
|
Originally posted by Cheng Wei Lee: You're brilliant!
Not brilliant, just too lazy to write a bunch of code
|
 |
Chengwei Lee
Ranch Hand
Joined: Apr 02, 2004
Posts: 884
|
|
Originally posted by Tom Blough: Not brilliant, just too lazy to write a bunch of code
If laziness can drive you to come out with short & elegant codes, I say, go ahead & be lazy! Thanks for teaching me something new!
|
 |
Greg T Robertson
Ranch Hand
Joined: Nov 18, 2003
Posts: 91
|
|
|
Be aware that if you are using the Calendar to get your month it already has 1 subtracted from it as January is 0
|
 |
 |
|
|
subject: getting the current quarter
|
|
|