Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.asn1.eac;
  
  import java.util.Date;
  import java.util.Locale;
  
EAC encoding date object
 
 public class PackedDate
 {
     private byte[]      time;
 
     public PackedDate(
         String time)
     {
         this. = convert(time);
     }

    
Base constructor from a java.util.date object.

Parameters:
time a date object representing the time of interest.
 
     public PackedDate(
         Date time)
     {
         SimpleDateFormat dateF = new SimpleDateFormat("yyMMdd'Z'");
 
         dateF.setTimeZone(new SimpleTimeZone(0,"Z"));
 
         this. = convert(dateF.format(time));
     }

    
Base constructor from a java.util.date object. You may need to use this constructor if the default locale doesn't use a Gregorian calender so that the PackedDate produced is compatible with other ASN.1 implementations.

Parameters:
time a date object representing the time of interest.
locale an appropriate Locale for producing an ASN.1 GeneralizedTime value.
 
     public PackedDate(
         Date time,
         Locale locale)
     {
         SimpleDateFormat dateF = new SimpleDateFormat("yyMMdd'Z'"locale);
 
         dateF.setTimeZone(new SimpleTimeZone(0,"Z"));
 
         this. = convert(dateF.format(time));
     }
 
     private byte[] convert(String sTime)
     {
         char[] digs = sTime.toCharArray();
         byte[] date = new byte[6];
 
         for (int i = 0; i != 6; i++)
         {
             date[i] = (byte)(digs[i] - '0');
         }
 
         return date;
     }
 
     PackedDate(
         byte[] bytes)
     {
         this. = bytes;
     }

    
return the time as a date based on whatever a 2 digit year will return. For standardised processing use getAdjustedDate().

Returns:
the resulting date
Throws:
java.text.ParseException if the date string cannot be parsed.
 
     public Date getDate()
         throws ParseException
     {
         SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMdd");
 
         return dateF.parse("20" + toString());
     }
 
     public int hashCode()
     {
         return Arrays.hashCode();
     }
 
     public boolean equals(Object o)
     {
         if (!(o instanceof PackedDate))
         {
            return false;
        }
        PackedDate other = (PackedDate)o;
        return Arrays.areEqual(other.time);
    }
    public String toString() 
    {
        char[]  dateC = new char[.];
        for (int i = 0; i != dateC.lengthi++)
        {
            dateC[i] = (char)(([i] & 0xff) + '0');
        }
        return new String(dateC);
    }
    public byte[] getEncoding()
    {
        return ;
    }
New to GrepCode? Check out our FAQ X