@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class ASN1UTCTime extends ASN1Element
SimpleDateFormat
class, which infers the century using a
sliding window that assumes that the year is somewhere between 80 years
before and 20 years after the current time. For example, if the current year
is 2017, the following values would be inferred:
ASN1GeneralizedTime
element type does use a four-digit year (and also
allows for the possibility of sub-second values), so it may be a good fit.
You may also want to use a general-purpose string format like
ASN1OctetString
that is flexible enough to support whatever encoding
you want.Constructor and Description |
---|
ASN1UTCTime()
Creates a new UTC time element with the default BER type that represents
the current time.
|
ASN1UTCTime(byte type)
Creates a new UTC time element with the specified BER type that represents
the current time.
|
ASN1UTCTime(byte type,
java.util.Date date)
Creates a new UTC time element with the specified BER type that represents
the indicated time.
|
ASN1UTCTime(byte type,
long time)
Creates a new UTC time element with the specified BER type that represents
the indicated time.
|
ASN1UTCTime(byte type,
java.lang.String timestamp)
Creates a new UTC time element with the specified BER type and a time
decoded from the provided string representation.
|
ASN1UTCTime(java.util.Date date)
Creates a new UTC time element with the default BER type that represents
the indicated time.
|
ASN1UTCTime(long time)
Creates a new UTC time element with the default BER type that represents
the indicated time.
|
ASN1UTCTime(java.lang.String timestamp)
Creates a new UTC time element with the default BER type and a time decoded
from the provided string representation.
|
Modifier and Type | Method and Description |
---|---|
static ASN1UTCTime |
decodeAsUTCTime(ASN1Element element)
Decodes the provided ASN.1 element as a UTC time element.
|
static ASN1UTCTime |
decodeAsUTCTime(byte[] elementBytes)
Decodes the contents of the provided byte array as a UTC time element.
|
static long |
decodeTimestamp(java.lang.String timestamp)
Decodes the provided string as a timestamp in the UTC time format.
|
static java.lang.String |
encodeTimestamp(java.util.Date date)
Encodes the time represented by the provided date into the appropriate
ASN.1 UTC time format.
|
static java.lang.String |
encodeTimestamp(long time)
Encodes the specified time into the appropriate ASN.1 UTC time format.
|
java.util.Date |
getDate()
Retrieves a
Date object that is set to the time represented by this
UTC time element. |
java.lang.String |
getStringRepresentation()
Retrieves the string representation of the UTC time value contained in this
element.
|
long |
getTime()
Retrieves the time represented by this UTC time element, expressed as the
number of milliseconds since the epoch (the same format used by
System.currentTimeMillis() and Date.getTime() ). |
void |
toString(java.lang.StringBuilder buffer)
Appends a string representation of the value for this ASN.1 element to the
provided buffer.
|
decode, decodeAsBigInteger, decodeAsBitString, decodeAsBoolean, decodeAsEnumerated, decodeAsGeneralizedTime, decodeAsIA5String, decodeAsInteger, decodeAsLong, decodeAsNull, decodeAsNumericString, decodeAsObjectIdentifier, decodeAsOctetString, decodeAsPrintableString, decodeAsSequence, decodeAsSet, decodeAsUTCTime, decodeAsUTF8String, encode, encodeLength, encodeTo, equals, equalsIgnoreType, getType, getTypeClass, getValue, getValueLength, hashCode, isConstructed, readFrom, readFrom, toString, writeTo
public ASN1UTCTime()
public ASN1UTCTime(byte type)
type
- The BER type to use for this element.public ASN1UTCTime(@NotNull java.util.Date date)
date
- The date value that specifies the time to represent. This
must not be null
. Note that the time that is
actually represented by the element will have its
milliseconds component set to zero.public ASN1UTCTime(byte type, @NotNull java.util.Date date)
type
- The BER type to use for this element.date
- The date value that specifies the time to represent. This
must not be null
. Note that the time that is
actually represented by the element will have its
milliseconds component set to zero.public ASN1UTCTime(long time)
time
- The time to represent. This must be expressed in
milliseconds since the epoch (the same format used by
System.currentTimeMillis()
and
Date.getTime()
). Note that the time that is actually
represented by the element will have its milliseconds
component set to zero.public ASN1UTCTime(byte type, long time)
type
- The BER type to use for this element.time
- The time to represent. This must be expressed in
milliseconds since the epoch (the same format used by
System.currentTimeMillis()
and
Date.getTime()
). Note that the time that is actually
represented by the element will have its milliseconds
component set to zero.public ASN1UTCTime(@NotNull java.lang.String timestamp) throws ASN1Exception
timestamp
- The string representation of the timestamp to represent.
This must not be null
.ASN1Exception
- If the provided timestamp does not represent a
valid ASN.1 UTC time string representation.public ASN1UTCTime(byte type, @NotNull java.lang.String timestamp) throws ASN1Exception
type
- The BER type to use for this element.timestamp
- The string representation of the timestamp to represent.
This must not be null
.ASN1Exception
- If the provided timestamp does not represent a
valid ASN.1 UTC time string representation.@NotNull public static java.lang.String encodeTimestamp(@NotNull java.util.Date date)
date
- The date value that specifies the time to represent. This
must not be null
.@NotNull public static java.lang.String encodeTimestamp(long time)
time
- The time to represent. This must be expressed in
milliseconds since the epoch (the same format used by
System.currentTimeMillis()
and
Date.getTime()
).public static long decodeTimestamp(@NotNull java.lang.String timestamp) throws ASN1Exception
timestamp
- The string representation of a UTC time to be parsed as
a timestamp. It must not be null
.System.currentTimeMillis()
and
Date.getTime()
).ASN1Exception
- If the provided timestamp cannot be parsed as a
valid string representation of an ASN.1 UTC time
value.public long getTime()
System.currentTimeMillis()
and Date.getTime()
).@NotNull public java.util.Date getDate()
Date
object that is set to the time represented by this
UTC time element.Date
object that is set ot the time represented by this
UTC time element.@NotNull public java.lang.String getStringRepresentation()
@NotNull public static ASN1UTCTime decodeAsUTCTime(@NotNull byte[] elementBytes) throws ASN1Exception
elementBytes
- The byte array to decode as an ASN.1 UTC time
element.ASN1Exception
- If the provided array cannot be decoded as a UTC
time element.@NotNull public static ASN1UTCTime decodeAsUTCTime(@NotNull ASN1Element element) throws ASN1Exception
element
- The ASN.1 element to be decoded.ASN1Exception
- If the provided element cannot be decoded as a UTC
time element.public void toString(@NotNull java.lang.StringBuilder buffer)
toString
in class ASN1Element
buffer
- The buffer to which to append the information.