Example usage for org.bouncycastle.asn1.x509 Time getTime

List of usage examples for org.bouncycastle.asn1.x509 Time getTime

Introduction

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

Prototype

public String getTime() 

Source Link

Usage

From source file:net.wstech2.me.httpsclient.CertificateValidatorUtils.java

License:Apache License

/**
 * Receives an org.bouncycastle.asn1.x509.Time returning a java.util.Date
 * instance corresponding to the same timestamp as the
 * org.bouncycastle.asn1.x509.Time informed.
 * /*  w ww  .  j  a v  a2s .c  o m*/
 * @param time
 *            An instance of org.bouncycastle.asn1.x509.Time containing a
 *            given Date.
 * 
 * @return An instance of java.util.Date representing the same timestamp
 *         from time.
 */
public static Date getDateFromX509Time(Time time) {
    Calendar retval = Calendar.getInstance();

    String timeString = time.getTime();

    Integer year = Integer.valueOf(timeString.substring(0, 4));
    Integer month = Integer.valueOf(timeString.substring(4, 6));
    Integer day = Integer.valueOf(timeString.substring(6, 8));
    Integer hour = Integer.valueOf(timeString.substring(8, 10));
    Integer minute = Integer.valueOf(timeString.substring(10, 12));
    Integer second = Integer.valueOf(timeString.substring(12, 14));

    retval.set(Calendar.YEAR, year.intValue());
    retval.set(Calendar.MONTH, month.intValue() - 1);
    retval.set(Calendar.DAY_OF_MONTH, day.intValue());
    retval.set(Calendar.HOUR_OF_DAY, hour.intValue());
    retval.set(Calendar.MINUTE, minute.intValue());
    retval.set(Calendar.SECOND, second.intValue());

    return retval.getTime();
}