1 17 package org.alfresco.filesys.ftp; 18 19 import java.util.*; 20 21 26 public class FTPDate 27 { 28 29 33 protected final static long SIX_MONTHS = 183L * 24L * 60L * 60L * 1000L; 34 35 37 protected final static String [] _months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", 38 "Nov", "Dec" }; 39 40 47 public final static void packUnixDate(StringBuffer buf, Date dt) 48 { 49 50 52 if (dt == null) 53 { 54 buf.append("------------"); 55 return; 56 } 57 58 60 long timeVal = dt.getTime(); 61 if (timeVal < 0) 62 { 63 buf.append("------------"); 64 return; 65 } 66 67 69 Calendar cal = new GregorianCalendar(); 70 cal.setTime(dt); 71 buf.append(_months[cal.get(Calendar.MONTH)]); 72 buf.append(" "); 73 74 int dayOfMonth = cal.get(Calendar.DATE); 75 if (dayOfMonth < 10) 76 buf.append(" "); 77 buf.append(dayOfMonth); 78 buf.append(" "); 79 80 82 long timeNow = System.currentTimeMillis(); 83 if (Math.abs(timeNow - timeVal) > SIX_MONTHS) 84 { 85 86 88 buf.append(cal.get(Calendar.YEAR)); 89 } 90 else 91 { 92 93 95 int hr = cal.get(Calendar.HOUR_OF_DAY); 96 if (hr < 10) 97 buf.append("0"); 98 buf.append(hr); 99 buf.append(":"); 100 101 int sec = cal.get(Calendar.SECOND); 102 if (sec < 10) 103 buf.append("0"); 104 buf.append(sec); 105 } 106 } 107 } 108 | Popular Tags |