1 21 22 27 28 package com.sun.mail.imap.protocol; 29 30 import java.util.Date ; 31 import java.util.TimeZone ; 32 import java.util.Locale ; 33 import java.text.ParseException ; 34 import java.text.SimpleDateFormat ; 35 import java.text.FieldPosition ; 36 37 import javax.mail.internet.MailDateFormat ; 38 39 import com.sun.mail.iap.*; 40 41 42 48 49 public class INTERNALDATE implements Item { 50 51 public static char [] name = {'I','N','T','E','R','N','A','L','D','A','T','E'}; 52 public int msgno; 53 protected Date date; 54 55 62 private static MailDateFormat mailDateFormat = new MailDateFormat (); 63 64 67 public INTERNALDATE(FetchResponse r) throws ParsingException { 68 msgno = r.getNumber(); 69 r.skipSpaces(); 70 String s = r.readString(); 71 try { 72 date = mailDateFormat.parse(s); 73 } catch (ParseException pex) { 74 throw new ParsingException("INTERNALDATE parse error"); 75 } 76 } 77 78 public Date getDate() { 79 return date; 80 } 81 82 84 private static SimpleDateFormat df = 85 new SimpleDateFormat ("dd-MMM-yyyy HH:mm:ss ", Locale.US); 88 89 92 public static String format(Date d) { 93 104 StringBuffer sb = new StringBuffer (); 105 synchronized (df) { 106 df.format(d, sb, new FieldPosition (0)); 107 } 108 109 int rawOffsetInMins = -d.getTimezoneOffset(); 112 119 if (rawOffsetInMins < 0) { 120 sb.append('-'); 121 rawOffsetInMins = (-rawOffsetInMins); 122 } else 123 sb.append('+'); 124 125 int offsetInHrs = rawOffsetInMins / 60; 126 int offsetInMins = rawOffsetInMins % 60; 127 128 sb.append(Character.forDigit((offsetInHrs/10), 10)); 129 sb.append(Character.forDigit((offsetInHrs%10), 10)); 130 sb.append(Character.forDigit((offsetInMins/10), 10)); 131 sb.append(Character.forDigit((offsetInMins%10), 10)); 132 133 return sb.toString(); 134 } 135 } 136 | Popular Tags |