1 16 package org.apache.commons.lang.time; 17 18 import java.util.Date ; 19 import java.util.Locale ; 20 import java.util.TimeZone ; 21 22 36 public class DateFormatUtils { 37 38 42 public static final FastDateFormat ISO_DATETIME_FORMAT 43 = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss"); 44 45 49 public static final FastDateFormat ISO_DATETIME_TIME_ZONE_FORMAT 50 = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ssZZ"); 51 52 56 public static final FastDateFormat ISO_DATE_FORMAT 57 = FastDateFormat.getInstance("yyyy-MM-dd"); 58 59 65 public static final FastDateFormat ISO_DATE_TIME_ZONE_FORMAT 66 = FastDateFormat.getInstance("yyyy-MM-ddZZ"); 67 68 72 public static final FastDateFormat ISO_TIME_FORMAT 73 = FastDateFormat.getInstance("'T'HH:mm:ss"); 74 75 79 public static final FastDateFormat ISO_TIME_TIME_ZONE_FORMAT 80 = FastDateFormat.getInstance("'T'HH:mm:ssZZ"); 81 82 88 public static final FastDateFormat ISO_TIME_NO_T_FORMAT 89 = FastDateFormat.getInstance("HH:mm:ss"); 90 91 97 public static final FastDateFormat ISO_TIME_NO_T_TIME_ZONE_FORMAT 98 = FastDateFormat.getInstance("HH:mm:ssZZ"); 99 100 104 public static final FastDateFormat SMTP_DATETIME_FORMAT 105 = FastDateFormat.getInstance("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US); 106 107 114 public DateFormatUtils() { 115 } 116 117 124 public static String formatUTC(long millis, String pattern) { 125 return format(new Date (millis), pattern, DateUtils.UTC_TIME_ZONE, null); 126 } 127 128 135 public static String formatUTC(Date date, String pattern) { 136 return format(date, pattern, DateUtils.UTC_TIME_ZONE, null); 137 } 138 139 147 public static String formatUTC(long millis, String pattern, Locale locale) { 148 return format(new Date (millis), pattern, DateUtils.UTC_TIME_ZONE, locale); 149 } 150 151 159 public static String formatUTC(Date date, String pattern, Locale locale) { 160 return format(date, pattern, DateUtils.UTC_TIME_ZONE, locale); 161 } 162 163 170 public static String format(long millis, String pattern) { 171 return format(new Date (millis), pattern, null, null); 172 } 173 174 181 public static String format(Date date, String pattern) { 182 return format(date, pattern, null, null); 183 } 184 185 193 public static String format(long millis, String pattern, TimeZone timeZone) { 194 return format(new Date (millis), pattern, timeZone, null); 195 } 196 197 205 public static String format(Date date, String pattern, TimeZone timeZone) { 206 return format(date, pattern, timeZone, null); 207 } 208 209 217 public static String format(long millis, String pattern, Locale locale) { 218 return format(new Date (millis), pattern, null, locale); 219 } 220 221 229 public static String format(Date date, String pattern, Locale locale) { 230 return format(date, pattern, null, locale); 231 } 232 233 242 public static String format(long millis, String pattern, TimeZone timeZone, Locale locale) { 243 return format(new Date (millis), pattern, timeZone, locale); 244 } 245 246 255 public static String format(Date date, String pattern, TimeZone timeZone, Locale locale) { 256 FastDateFormat df = FastDateFormat.getInstance(pattern, timeZone, locale); 257 return df.format(date); 258 } 259 260 } 261 | Popular Tags |