|
|
| java |
Expert:Tarunkanti Kar
how to add 45days in 02-Dec-2008 date format. |
| Answers |
Hi friend,
Code to solve the problem :
import java.util.Date; import java.util.Locale; import java.util.Calendar; import java.text.SimpleDateFormat;
public class AddDaysToDate {
public static Calendar parseTimestamp(String timestamp) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.US); Date d = sdf.parse(timestamp); Calendar cal = Calendar.getInstance(); cal.setTime(d); return cal; }
public static void main (String a[]) throws Exception{ String timestampToParse = "02-Dec-2008"; System.out.println("Date is : " + timestampToParse); Calendar cal = parseTimestamp(timestampToParse); cal.add(Calendar.DATE, 45); Date d = new Date(cal.getTime().getTime()); SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy"); String formattedDate = formatter.format(d); System.out.println("After 45 Days date is ==>"+formattedDate); } }
Vineet
|
| More Questions |
|
|
Post Answers
Ask Question
Facing Programming Problem?
|
|
|
|
|