View Single Post
  #1 (permalink)  
Old 03-30-2008, 10:47 AM
valoyivd valoyivd is offline
Member
 
Join Date: Mar 2008
Posts: 8
valoyivd is on a distinguished road
java Date and Calendar
I am new to Java , I have written this method in order to achieve the following!!!

I want to Calculate current date + 30 days. If calculated date = 1st of a month then use this date. If it is not the 1st of a month, then use the 1st of the following month.
Example…if today is 15 April 2007, then expiry date will be 1 June 2007.
If today is 2 May 2007, then expiry date will be 1 June 2007.

I want to simplify this code so that It looks pretty...
please help me to do that!!!!



Code:
import java.util.Calendar; /** * @author valoyi * */ public class CalcUti { @SuppressWarnings("unused") private static String getExpiaryDate(){ Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_MONTH, 30); int day = calendar.get(Calendar.DAY_OF_MONTH); if(day == 1){ return ""+ calendar; } else{ calendar.add(Calendar.MONTH,2); calendar.set(Calendar.DAY_OF_MONTH,1); return " " + calendar; } } }
Reply With Quote
Sponsored Links