Advertisement
enissay

Enissay

Feb 25th, 2015
241
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private String tryParse(String rd) {
  2.     SimpleDateFormat sdfRD = null;
  3.     Date d = null;
  4.  
  5.     // 4 Nov, 2014
  6.     // Nov, 2014
  7.     String[] oldFormatString = {"dd MMM, yyyy", "MMM, yyyy"};   // Multiple possible formats
  8.     String newFormatString = "yyyy-MM-dd";
  9.            
  10.     for (String formatString : oldFormatString) {
  11.         try {
  12.             sdfRD = new SimpleDateFormat(formatString, new Locale("us", "US"));
  13.             d = sdfRD.parse(rd);
  14.         }
  15.         catch (ParseException e) {
  16.             sdfRD = null;
  17.             d = null;
  18.         }
  19.  
  20.         sdfRD.applyPattern(newFormatString);
  21.         return(sdfRD.format(d));
  22.     }
  23.  
  24.     return null;
  25. }
Advertisement
RAW Paste Data Copied
Advertisement