Example usage for org.bouncycastle.asn1 DERGeneralizedTime getTime

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

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 DERGeneralizedTime 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:com.jlocksmith.util.ExtensionUtil.java

License:Open Source License

/**
 * Format Generalized Time/*from   w ww . ja v  a 2 s .  c  o m*/
 * 
 * @param time
 * 
 * @return String
 * 
 * @throws ParseException
 */
private String formatGeneralizedTime(DERGeneralizedTime 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 timezone
    sTime = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG).format(date);

    return sTime;
}

From source file:org.glite.voms.ac.AttributeCertificate.java

License:eu-egee.org license

private static Date getDate(DERGeneralizedTime time) throws ParseException {
    SimpleDateFormat dateF;/*  w w w.  j  av a  2s  . c o  m*/

    // BouncyCastle change the output of getTime() and instead
    // introduced a new method getDate() method... better make
    // sure we stay compatible 
    String t = time.getTime();

    if (t.indexOf("GMT") > 0) {
        dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
    } else {
        dateF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
        dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
    }

    return dateF.parse(time.getTime());
}