T
Tim Slattery
I'm retrieving a datetime value from my database. I can easily
retrieve this into a java.sql.Date object. Once retrieved, I want to
display the month and year from it in a yyyymm format. I also want to
calculate the four preceding months, and display them likewise. So if
I retrieve a date in September, 2003 from the DB, I want the following
five display strings: 200309, 200308, 200307, 200306, 200305.
So I can use Date.getYear() and Date.getMonth(), then manipulate them,
right? But those functions are deprecated, and we're supposed to use
Calendar.get(Calendar.YEAR) and Calendar.get(Calendar.MONTH).
Ok...Calendar includes a neat add(...) function that I can use to do
date arithmetic. But Calendar.get(Calendar.MONTH) returns one of the
constants defined within Calendar, and they could have any value; so
how do I format the string that I need? Hmm..there's a DateFormat
class....but I can't for the life of me figure out how to make it
yield the string that I need.
So what's the answer? Should I just give up and use the deprecated
functions from java.util.Date (which java.sql.Date extends)?
retrieve this into a java.sql.Date object. Once retrieved, I want to
display the month and year from it in a yyyymm format. I also want to
calculate the four preceding months, and display them likewise. So if
I retrieve a date in September, 2003 from the DB, I want the following
five display strings: 200309, 200308, 200307, 200306, 200305.
So I can use Date.getYear() and Date.getMonth(), then manipulate them,
right? But those functions are deprecated, and we're supposed to use
Calendar.get(Calendar.YEAR) and Calendar.get(Calendar.MONTH).
Ok...Calendar includes a neat add(...) function that I can use to do
date arithmetic. But Calendar.get(Calendar.MONTH) returns one of the
constants defined within Calendar, and they could have any value; so
how do I format the string that I need? Hmm..there's a DateFormat
class....but I can't for the life of me figure out how to make it
yield the string that I need.
So what's the answer? Should I just give up and use the deprecated
functions from java.util.Date (which java.sql.Date extends)?