For a DAY_IN_YEAR calculate YYYYMMDD If I have a DAY_IN_YEAR (say DIY == 199) (a) Get DAY_IN_YEAR now say DIYnow (b) Check if DIYnow > DIY then YYYY = THIS_YEAR_YYYY; else YYYY = THIS_YEAR_YYYY - 1; (c) Then for YYYY calculate MMDD for the given DIY (i.e for 199)
Do any of you know how to implement this in Java?
Cheers, Gurram
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
create a calendar instance add to the DATE field( -DAY_OF_YEAR + 199) use SimpleDateFormat() to display calendar.getTime() the way you want
Reddy Gurram
Greenhorn
Joined: Oct 19, 2004
Posts: 10
posted
0
Thanks Michael!
For some reason the following code is not printing the right DAY_IN_YEAR. Any ideas??? ////////////////////BGN///////////////////// public static void main(String[] args) { Calendar cal = java.util.GregorianCalendar.getInstance(); Calendar gCalYDay = GregorianCalendar.getInstance(); System.out.println("gCalYDay.DAY_OF_YEAR:" + gCalYDay.DAY_OF_YEAR); } ////////////////////END///////////////////// Output looks as below: -------------BGN----------------- gCalYDay.DAY_OF_YEAR:6 -------------END-----------------
Cheers, Gurram
Reddy Gurram
Greenhorn
Joined: Oct 19, 2004
Posts: 10
posted
0
Oops! Michael, What happens if (DIY == 365) and (DIYnow == 1) ??? Leap year or not?
Reddy Gurram
Greenhorn
Joined: Oct 19, 2004
Posts: 10
posted
0
I Guess I need to use the below logic... //////////////// bgn //////////////// DIY01_this_year_or_last_year = SOME_KNOWN_VALUE; find DIYnow; find DateNow;
if ( DIYnow > DIY01_this_year_or_last_year ){ // // Both DIYs in the same year // Date01 = DateNow - DIYnow + DIY01_this_year_or_last_year; } else { // // DIY01 is in last year // last_year = Get this_year-1; if (last_year LEAP_YEAR) {x = 366 - DIY01;} else {x = 365 - DIY01;} Date01 = DateNow - x - DIYnow; } //////////////// end ////////////////
For some reason still "gCalYDay.DAY_OF_MONTH" is not getting the actual DAY_IN_YEAR :-(.