1 11 package org.eclipse.team.internal.ccvs.core; 12 13 14 import java.text.ParseException ; 15 import java.text.SimpleDateFormat ; 16 import java.util.Date ; 17 import java.util.Locale ; 18 import java.util.TimeZone ; 19 20 23 public class DateUtil { 24 25 private static final String ENTRY_TIMESTAMP_FORMAT= "EEE MMM dd HH:mm:ss yyyy"; private static final String ENTRY_TIMESTAMP_TIME_ZONE= "GMT"; private static final Locale ENTRY_TIMESTAMP_LOCALE= Locale.US; 28 29 private static final String MODTIME_TIMESTAMP_FORMAT= "dd MMM yyyy HH:mm:ss zz"; private static final Locale MODTIME_TIMESTAMP_LOCALE= Locale.US; 31 32 private static final String LOG_TIMESTAMP_FORMAT= "yyyy/MM/dd HH:mm:ss zzz"; private static final Locale LOG_TIMESTAMP_LOCALE= Locale.US; 34 35 private static final String HISTORY_TIMESTAMP_FORMAT= "yyyy-MM-dd HH:mm zzzz"; private static final Locale HISTORY_TIMESTAMP_LOCALE= Locale.US; 37 38 42 public static Date convertFromLogTime(String modTime) { 43 SimpleDateFormat format= new SimpleDateFormat (LOG_TIMESTAMP_FORMAT, 44 LOG_TIMESTAMP_LOCALE); 45 try { 46 return format.parse(modTime); 47 } catch (ParseException e) { 48 return null; 50 } 51 } 52 57 public static Date convertFromModTime(String modTime) { 58 SimpleDateFormat format= new SimpleDateFormat (MODTIME_TIMESTAMP_FORMAT, 59 MODTIME_TIMESTAMP_LOCALE); 60 try { 61 return format.parse(modTime); 62 } catch (ParseException e) { 63 return null; 65 } 66 } 67 71 public static Date convertFromHistoryTime(String historyTime) { 72 SimpleDateFormat format= new SimpleDateFormat (HISTORY_TIMESTAMP_FORMAT, 73 HISTORY_TIMESTAMP_LOCALE); 74 try { 75 return format.parse(historyTime); 76 } catch (ParseException e) { 77 return null; 79 } 80 } 81 86 public static String toEntryFormat(Date date) { 87 SimpleDateFormat format= new SimpleDateFormat (ENTRY_TIMESTAMP_FORMAT, 88 ENTRY_TIMESTAMP_LOCALE); 89 format.setTimeZone(TimeZone.getTimeZone(ENTRY_TIMESTAMP_TIME_ZONE)); 90 return format.format(date); 91 } 92 } 93 | Popular Tags |