Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 18th, 2010 | Syntax: Java 5 | Size: 1.00 KB | Hits: 44 | Expires: Never
Copy text to clipboard
  1.         /**
  2.          * Converts a date-string into another date form.
  3.          *
  4.          * @param date
  5.          *                      to convert
  6.          * @param formFrom
  7.          *                      actual date form
  8.          * @param formTo
  9.          *                      new date form
  10.          * @return String  
  11.          */
  12.         public static String convert(String date, String[] formFrom, String[] formTo) {
  13.                 try {
  14.                         for (String dateFormatFrom : formFrom) {
  15.                                 for (String dateFormatTo : formTo) {
  16.                                         System.out.println(dateFormatFrom);
  17.                                         System.out.println(date);
  18.                                         if (dateFormatFrom.length() != date.length()){
  19.                                                 continue;
  20.                                         }
  21.                                         if (dateFormatTo.length() != dateFormatFrom.length() & date.length() == 10){
  22.                                                 continue;
  23.                                         }
  24.                                         System.out.println("dad");
  25.                                         SimpleDateFormat sdfFrom = new SimpleDateFormat(
  26.                                                         dateFormatFrom);
  27.                                         SimpleDateFormat sdfTo = new SimpleDateFormat(
  28.                                                         dateFormatTo);
  29.                                         Date pDate = sdfFrom.parse(date);
  30.                                         String converted = sdfTo.format(pDate);
  31.  
  32.                                         return converted;
  33.                                 }
  34.                         }
  35.                 } catch (ParseException e) {
  36.                 }
  37.                 return null;
  38.         }