1 28 29 package com.idaremedia.antx.helpers; 30 31 import java.text.FieldPosition ; 32 import java.text.Format ; 33 import java.text.SimpleDateFormat ; 34 import java.util.Date ; 35 import java.util.TimeZone ; 36 37 47 48 public final class DateTimeFormat 49 { 50 private DateTimeFormat() {} 51 52 53 public static final SimpleDateFormat ABBREV = new SimpleDateFormat ("dd-MMM h:mm a"); 54 55 56 public static final SimpleDateFormat ABBREV_DATE = new SimpleDateFormat ("dd-MMM"); 57 58 61 public static final SimpleDateFormat ABBREV_TIME = new SimpleDateFormat ("h:mm a"); 62 63 64 public static final SimpleDateFormat STANDARD = new SimpleDateFormat ("h:mm:ss a dd-MMM-yyyy"); 65 66 67 public static final SimpleDateFormat STANDARD_DATE = new SimpleDateFormat ("dd-MMM-yyyy"); 68 69 72 public static final SimpleDateFormat STANDARD_TIME = new SimpleDateFormat ("h:mm:ss a"); 73 74 77 public static final SimpleDateFormat CHANGELOG = new SimpleDateFormat ("dd MMM yyyy"); 78 79 80 public static final SimpleDateFormat GMT = new SimpleDateFormat ("k:mm:ss dd-MMM-yyyy 'GMT'"); 81 82 83 public static final SimpleDateFormat GMT_DATE = new SimpleDateFormat ("dd-MMM-yyyy 'GMT'"); 84 85 86 public static final SimpleDateFormat GMT_TIME = new SimpleDateFormat ("k:mm:ss 'GMT'"); 87 88 static { 89 TimeZone gmtz = TimeZone.getTimeZone("GMT"); 90 GMT.setTimeZone(gmtz); 91 GMT_DATE.setTimeZone(gmtz); 92 GMT_TIME.setTimeZone(gmtz); 93 } 94 95 96 103 public static String format(long tm, Format dfmt) { 104 if (dfmt==null) { 105 throw new IllegalArgumentException (); 106 } 107 synchronized(dfmt) { 108 sm_adhoc.setTime(tm); 109 return dfmt.format(sm_adhoc); 110 } 111 } 112 113 114 116 public static String format(long tm) { 117 synchronized(STANDARD) { 118 sm_standard.setTime(tm); 119 return STANDARD.format(sm_standard); 120 } 121 } 122 123 125 public static StringBuffer format(long tm, StringBuffer sb) { 126 synchronized(STANDARD) { 127 sm_standard.setTime(tm); 128 return STANDARD.format(sm_standard,sb,new FieldPosition (0)); 129 } 130 } 131 132 134 public static String shortformat(long tm) { 135 synchronized(ABBREV) { 136 sm_abbrev.setTime(tm); 137 return ABBREV.format(sm_abbrev); 138 } 139 } 140 141 143 public static StringBuffer shortformat(long tm, StringBuffer sb) { 144 synchronized(ABBREV) { 145 sm_abbrev.setTime(tm); 146 return ABBREV.format(sm_abbrev,sb,new FieldPosition (0)); 147 } 148 } 149 150 152 public static String GMTformat(long tm) { 153 synchronized(GMT) { 154 sm_GMT.setTime(tm); 155 return GMT.format(sm_GMT); 156 } 157 } 158 159 161 public static StringBuffer GMTformat(long tm, StringBuffer sb) { 162 synchronized(GMT) { 163 sm_GMT.setTime(tm); 164 return GMT.format(sm_GMT,sb,new FieldPosition (0)); 165 } 166 } 167 168 172 public static StringBuffer shortdate(long tm, StringBuffer sb) { 173 synchronized(ABBREV_DATE) { 174 Date dt = new Date (tm); 175 return ABBREV_DATE.format(dt,sb,new FieldPosition (0)); 176 } 177 } 178 179 183 public static String shortdate(long tm) { 184 synchronized(ABBREV_DATE) { 185 Date dt = new Date (tm); 186 return ABBREV_DATE.format(dt); 187 } 188 } 189 190 191 192 private static final Date sm_abbrev = new Date (); 193 private static final Date sm_standard = new Date (); 194 private static final Date sm_GMT = new Date (); 195 private static final Date sm_adhoc = new Date (); 196 } 197 198 199 | Popular Tags |