1 37 package net.sourceforge.cruisecontrol.util; 38 39 import java.text.DateFormat ; 40 import java.text.SimpleDateFormat ; 41 import java.util.Locale ; 42 43 47 public final class DateHelper { 48 49 private static final char YEAR = 'y'; 50 private static final char DAY = 'd'; 51 private static final char MONTH = 'M'; 52 private static final String TWENTY_FOUR_HOUR = " HH:mm:ss"; 53 private static final SimpleDateFormat YEAR_FORMAT = new SimpleDateFormat ("yyyy/MM/dd" + TWENTY_FOUR_HOUR); 54 private static final SimpleDateFormat DAY_FORMAT = new SimpleDateFormat ("dd/MM/yyyy" + TWENTY_FOUR_HOUR); 55 private static final SimpleDateFormat MONTH_FORMAT = new SimpleDateFormat ("MM/dd/yyyy" + TWENTY_FOUR_HOUR); 56 57 private DateHelper() { 58 } 60 61 66 public static SimpleDateFormat createDateFormat(Locale locale) { 67 SimpleDateFormat standardFormat = (SimpleDateFormat ) DateFormat.getDateInstance(DateFormat.SHORT, locale); 68 String standardPattern = standardFormat.toPattern(); 69 char firstLetterInPattern = standardPattern.charAt(0); 70 switch (firstLetterInPattern) { 71 case MONTH: 72 return MONTH_FORMAT; 73 case DAY: 74 return DAY_FORMAT; 75 case YEAR: 76 return YEAR_FORMAT; 77 default: 78 return new SimpleDateFormat (standardPattern + TWENTY_FOUR_HOUR); 79 } 80 } 81 } 82 | Popular Tags |