1 19 package org.openharmonise.webdav.date; 20 21 import java.text.ParseException ; 22 import java.text.SimpleDateFormat ; 23 import java.util.Date ; 24 25 33 public class DateFormatter { 34 35 private static Date m_Date = null; 36 37 private static String m_sRFCFormat = "EEE, dd MMM yyyy HH:mm:ss"; 38 39 private static String m_sISOFormat = "yyyy-MM-dd'T'HH:mm:ss"; 40 41 44 public DateFormatter() { 45 } 46 47 53 public static String format(String sDate, String sFormat) 54 throws ParseException { 55 SimpleDateFormat df; 56 df = new SimpleDateFormat (m_sRFCFormat); 58 try { 59 m_Date = df.parse(sDate); 60 } catch (ParseException e) { 61 } 63 if (m_Date == null) { 64 df = new SimpleDateFormat (m_sISOFormat); 66 try { 67 m_Date = df.parse(sDate); 68 } catch (ParseException e1) { 69 throw new ParseException ( 70 "Date is neither SimpleRFC1123DateFormat" 71 + " nor a SimpleISO8601DateFormat", 0); 72 } 73 } 74 df = new SimpleDateFormat (sFormat); 75 return df.format(m_Date); 76 } 77 } | Popular Tags |