| Author |
How to convert Number of Days to MM and DD
|
caartic sub
Greenhorn
Joined: Apr 20, 2011
Posts: 2
|
|
Hi,
I am looking for a conversion logic that could convert the number of days to months & days.
e.g: If CCYY = 2011 and JJJ = 100, the converted CCYYMMDD should look like: 20110409
Thanks in advance.
|
 |
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2816
|
|
|
Both GregorianCalendar can do calculations with day of year (which seems to be what your JJJ number represents) as well as other more common fields like month and day of month. Either could be used to solve this. If the inputs and outputs are text, I'd probably use SimpleDateFormat; otherwise GregorianCalendar.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
Welcome to the Ranch!
Check out java.util.Calendar:
But you'll find that returns 20110410, not 20110409. That's because April 10th is the 100th day of the year: 31 for January, 28 for February and 31 for March makes 90. That leaves 10 for April.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
caartic sub
Greenhorn
Joined: Apr 20, 2011
Posts: 2
|
|
@Mike: Thanks.
@Rob: Thanks a lot. Worked like a charm.
|
 |
 |
|
|
subject: How to convert Number of Days to MM and DD
|
|
|