1 package nl.hippo.cms.workflows.shared; 2 3 import java.text.DateFormat ; 4 import java.text.ParseException ; 5 import java.text.SimpleDateFormat ; 6 import java.util.Date ; 7 8 public class WorkflowExtensionUtil 9 { 10 11 public static Date getDate(Object dateAsUnknown) 12 { 13 Date result = null; 14 if (dateAsUnknown instanceof Date ) 15 { 16 result = (Date ) dateAsUnknown; 17 } 18 else if (dateAsUnknown instanceof String ) 19 { 20 DateFormat df = new SimpleDateFormat ("yyyyMMdd"); 21 try 22 { 23 result = df.parse((String ) dateAsUnknown); 24 } 25 catch (ParseException e) 26 { 27 } 29 } 30 return result; 31 } 32 33 public static Date getDateAndTime(Object dateAsUnknown) 34 { 35 Date result = null; 36 if (dateAsUnknown instanceof Date ) 37 { 38 result = (Date ) dateAsUnknown; 39 } 40 else if (dateAsUnknown instanceof String ) 41 { 42 try 43 { 44 String dateAsString = (String ) dateAsUnknown; 45 if (dateAsString.length() == 8) 46 { 47 DateFormat dateFormat = new SimpleDateFormat ("yyyyMMdd"); 48 result = dateFormat.parse(dateAsString); 49 } 50 else 51 { 52 DateFormat dateAndTimeFormat = new SimpleDateFormat ("yyyyMMddHHmm"); 53 result = dateAndTimeFormat.parse(dateAsString); 54 } 55 } 56 catch (ParseException e) 57 { 58 } 60 } 61 return result; 62 } 63 64 private WorkflowExtensionUtil() 65 { 66 super(); 67 } 68 69 } 70 | Popular Tags |