1 18 package org.apache.beehive.netui.tools.testrecorder.shared.util; 19 20 import org.apache.beehive.netui.tools.testrecorder.server.state.Session; 21 22 import java.text.SimpleDateFormat ; 23 import java.text.ParseException ; 24 25 import java.util.Calendar ; 26 import java.util.Locale ; 27 import java.util.Date ; 28 29 32 public class DateHelper 33 { 34 39 private static final Locale DEFAULT_LOCALE = Locale.US; 40 41 44 private static final String DATE_FORMAT_STRING = "dd MMM yyyy, hh:mm:ss.SSS aa zzz"; 45 46 51 private static final String READABLE_DATE_FORMAT_STRING = "dd MMM, hh:mm:ss aa"; 52 53 56 private static final SimpleDateFormat XML_DATE_FORMAT = new SimpleDateFormat (DATE_FORMAT_STRING, DEFAULT_LOCALE); 57 58 61 private static final SimpleDateFormat READABLE_DATE_FORMAT = new SimpleDateFormat (READABLE_DATE_FORMAT_STRING, DEFAULT_LOCALE); 62 63 64 private DateHelper() {} 66 67 72 public static final Calendar getCalendarInstance() 73 { 74 return Calendar.getInstance(DEFAULT_LOCALE); 75 } 76 77 85 public static final Calendar getCalendarInstance(String dateString) 86 throws ParseException 87 { 88 assert dateString != null; 89 90 Calendar calendar = Calendar.getInstance(DEFAULT_LOCALE); 91 calendar.setTime(XML_DATE_FORMAT.parse(dateString)); 92 93 return calendar; 94 } 95 96 103 public static final String formatToString(Calendar calendar) 104 { 105 assert calendar != null; 106 return XML_DATE_FORMAT.format(calendar.getTime()); 107 } 108 109 116 public static final String formatToString(Date date) 117 { 118 assert date != null; 119 return XML_DATE_FORMAT.format(date); 120 } 121 122 128 public static final String formatToReadableString(Date date) 129 { 130 assert date != null; 131 return READABLE_DATE_FORMAT.format(date); 132 } 133 } 134 | Popular Tags |