1 25 package org.ofbiz.service.calendar; 26 27 import java.text.ParsePosition ; 28 import java.text.SimpleDateFormat ; 29 import java.util.ArrayList ; 30 import java.util.Calendar ; 31 import java.util.Date ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 35 42 public class RecurrenceUtil { 43 44 45 public static Date parseDate(String dateStr) { 46 String formatString = new String (); 47 48 if (dateStr.length() == 16) 49 dateStr = dateStr.substring(0, 14); 50 if (dateStr.length() == 15) 51 formatString = "yyyyMMdd'T'hhmmss"; 52 if (dateStr.length() == 8) 53 formatString = "yyyyMMdd"; 54 55 SimpleDateFormat formatter = new SimpleDateFormat (formatString); 56 ParsePosition pos = new ParsePosition (0); 57 58 return formatter.parse(dateStr, pos); 59 } 60 61 62 public static List parseDateList(List dateList) { 63 List newList = new ArrayList (); 64 65 if (dateList == null) 66 return newList; 67 Iterator i = dateList.iterator(); 68 69 while (i.hasNext()) 70 newList.add(parseDate((String ) i.next())); 71 return newList; 72 } 73 74 75 public static String formatDate(Date date) { 76 String formatString = new String (); 77 Calendar cal = Calendar.getInstance(); 78 79 cal.setTime(date); 80 if (cal.isSet(Calendar.MINUTE)) 81 formatString = "yyyyMMdd'T'hhmmss"; 82 else 83 formatString = "yyyyMMdd"; 84 SimpleDateFormat formatter = new SimpleDateFormat (formatString); 85 86 return formatter.format(date); 87 } 88 89 90 public static List formatDateList(List dateList) { 91 List newList = new ArrayList (); 92 Iterator i = dateList.iterator(); 93 94 while (i.hasNext()) 95 newList.add(formatDate((Date ) i.next())); 96 return newList; 97 } 98 99 100 public static long now() { 101 return (new Date ()).getTime(); 102 } 103 104 } 105 106 | Popular Tags |