Google Analytics

Tuesday, May 27, 2014

JAVA Date format

String expireDate = "5";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Calendar c = Calendar.getInstance();c.setTime(new Date()); // Now use today date.
 c.add(Calendar.DATE, Integer.parseInt(expireDate)); // Adding days
 c.add(Calendar.YEAR, 1);
 String output = sdf.format(c.getTime());
  System.out.println(output);

Output
201X-06-02 09:52:16

No comments:

Post a Comment