Example usage for org.bouncycastle.asn1 ASN1GeneralizedTime getTime

List of usage examples for org.bouncycastle.asn1 ASN1GeneralizedTime getTime

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 ASN1GeneralizedTime getTime.

Prototype

public String getTime() 

Source Link

Document

return the time - always in the form of YYYYMMDDhhmmssGMT(+hh:mm|-hh:mm).

Usage

From source file:net.sf.keystore_explorer.utilities.asn1.Asn1Dump.java

License:Open Source License

private String dumpGeneralizedTime(ASN1GeneralizedTime asn1Time) {
    StringBuilder sb = new StringBuilder();

    sb.append(indentSequence.toString(indentLevel));
    sb.append("GENERALIZED TIME=");

    Date date;/* ww  w.  j a  va 2 s  . c  o  m*/
    try {
        date = asn1Time.getDate();
    } catch (ParseException e) {
        throw new RuntimeException("Cannot parse generalized time");
    }
    String formattedDate = new SimpleDateFormat("dd/MMM/yyyy HH:mm:ss.SSS z").format(date);

    sb.append(formattedDate);
    sb.append(" (");
    sb.append(asn1Time.getTime());
    sb.append(")");
    sb.append(NEWLINE);

    return sb.toString();
}

From source file:net.sf.portecle.crypto.X509Ext.java

License:Open Source License

/**
 * Get a formatted string value for the supplied generalized time object.
 * //from   w  w  w .  ja  va  2s.  c  o m
 * @param time Generalized time
 * @return Formatted string
 * @throws ParseException If there is a problem formatting the generalized time
 */
private String formatGeneralizedTime(ASN1GeneralizedTime time) throws ParseException {
    // Get generalized time as a string
    String sTime = time.getTime();

    // Setup date formatter with expected date format of string
    DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssz");

    // Create date object from string using formatter
    Date date = dateFormat.parse(sTime);

    // Re-format date - include time zone
    sTime = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG).format(date);

    return escapeHtml(sTime);
}