1 package org.bouncycastle.asn1;
10 public class DERUTCTime
16 * The correct format for this is YYMMDDHHMMSSZ (it used to be that seconds were
17 * never encoded. When you're creating one of these objects from scratch, that's
18 * what you want to use, otherwise we'll try to deal with whatever gets read from
19 * the input stream... (this is why the input format is different from the getTime()
22 * You can generate a Java date string in the right format by using:
24 * dateF = new SimpleDateFormat("yyMMddHHmmss");
25 * tz = new SimpleTimeZone(0, "Z");
27 * dateF.setTimeZone(tz);
29 * utcTime = new DERUTCTime(dateF.format(new Date()) + "Z");
32 * @param time the time string.
41 * return the time - always in the form of
42 * YYMMDDhhmmssGMT(+hh:mm|-hh:mm).
44 * Normally in a certificate we would expect "Z" rather than "GMT",
45 * however adding the "GMT" means we can just use:
47 * dateF = new SimpleDateFormat("yyMMddHHmmssz");
49 * To read in the time and get a date which is compatible with our local
52 public String getTime()
55 // standardise the format.
57 if (time.length() == 11)
59 return time.substring(0, 10) + "00GMT+00:00";
61 else if (time.length() == 13)
63 return time.substring(0, 12) + "GMT+00:00";
65 else if (time.length() == 17)
67 return time.substring(0, 12) + "GMT" + time.substring(12, 15) + ":" + time.substring(15, 17);
77 out.writeEncoded(UTC_TIME, time.getBytes());