[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [iaik-jce] UTF-Signing Time




Hi,

Z stands for Zulu, or GMT time.
I had the same problem and also did not find an easy way to create a Date
from it.

This is what I use for the moment:
    /**
     * Convert a given UTCTime to a Date.
     * Supported UTCTime format:
     *   - YYMMDDHHMMSSZ
     *     (ex.: 950307131426Z, meaning: 7 March 1995 13:14:26 Zulu time
(GMT))
     *   Note: if YY >= 50  year = 19YY
     *         else         year = 20YY
     *
     * @parm strUTCTime UTCTime as a String.
     * @param logger Log object to log to. May be null.
     * @return UTCTime converted to Date.
     */
    public static Date getDateFromUTCTime(String strUTCTime, Logger logger)
                                                        throws
InvalidParameterException {
        // First check on input parameter
        if (strUTCTime.length() < 13 || strUTCTime.charAt(12) != 'Z') {
            log(logger, "Invalid or unsupported UTCTime format: " +
strUTCTime, Logger.WARNING);
            throw new InvalidParameterException("Invalid or unsupported
UTCTime format: " +
                                                strUTCTime);
        }

        // Create GMT calendar
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));

        // Parse UTCTime
        try {
            int iY = Integer.parseInt(strUTCTime.substring(0, 2));
            if (iY >= 50) {
                iY += 1900;
            } else {
                iY += 2000;
            }
            int iM = Integer.parseInt(strUTCTime.substring(2, 4));
            int iD = Integer.parseInt(strUTCTime.substring(4, 6));
            int iH = Integer.parseInt(strUTCTime.substring(6, 8));
            int iMin = Integer.parseInt(strUTCTime.substring(8, 10));
            int iSec = Integer.parseInt(strUTCTime.substring(10, 12));
            // Month is zero-based !!
            cal.set(iY, iM-1, iD, iH, iMin, iSec);

            return cal.getTime();
        //} catch (NumberFormatException exc) {  // If substring cannot be
parsed to integer
        } catch (Exception exc) {
            log(logger, "Invalid or unsupported UTCTime format: " +
strUTCTime, Logger.WARNING);
            throw new InvalidParameterException("Invalid or unsupported
UTCTime format: " +
                                                strUTCTime);
        }
    }


Dirk.



                                                                                                                             
                    christoph_moser@gmx.de                                                                                   
                    Sent by:                       To:     iaik-jce@iaik.at                                                  
                    iaik-jce-owner@iaik.tu-        cc:                                                                       
                    graz.ac.at                     Subject:     [iaik-jce] UTF-Signing Time                                  
                                                                                                                             
                                                                                                                             
                    13/03/01 14:12                                                                                           
                                                                                                                             
                                                                                                                             




Hello,

while parsing the signing-attributes I read the signing time in UTF. I get
a value like 010312135550Z for a message signed yesterday. How do I
translate this time into a Date. When a make a date of this number without
the 'Z' I get 'Thu Apr 30 10:28:55 GMT+02:00 1970'. So what does the 'Z'
mean ?

Many thanks for your help in advance.

Regards

  Christoph


--
Sent through GMX FreeMail - http://www.gmx.net

--
Mailinglist-archive at
http://jcewww.iaik.at/mailarchive/iaik-jce/jcethreads.html

To unsubscribe send an email to listserv@iaik.at with the folowing content:
UNSUBSCRIBE iaik-jce




--
Mailinglist-archive at http://jcewww.iaik.at/mailarchive/iaik-jce/jcethreads.html

To unsubscribe send an email to listserv@iaik.at with the folowing content: UNSUBSCRIBE iaik-jce