Monday 16 September 2013

Java: Change one date format to another formate


  1. static public String FormatDate(String input) throws ParseException {

  2.         if (input != null) {
  3.             SimpleDateFormat oldFormate = new SimpleDateFormat();
  4.             oldFormate.applyPattern("yyyyMMddHHmmss");
  5.             //  System.out.println("input::"+input);

  6.             Date dt = oldFormate.parse(input);
  7.             // System.out.println("Date::"+dt);
  8.             SimpleDateFormat newFormate = new SimpleDateFormat();
  9.             newFormate.applyPattern("dd-MM-yyyy HH:mm:ss");

  10.             return newFormate.format(dt);
  11.         }
  12.         else
  13.         {
  14.             return input;
  15.         }
  16.     }

No comments: