Package org.webpki.util
Class ISODateTime
java.lang.Object
org.webpki.util.ISODateTime
Encodes/decodes ISO
dateTime
objects.
Always: yyyy-mm-ddThh:mm:ss
Optionally: a '.'
followed by 1-9
digits holding fractions of a second
Finally: 'Z'
for UTC or an UTC time-zone difference
expressed as ±hh:mm
.
ISO dateTime | Description |
---|---|
2022-12-24T05:45:23-08:00 | Local dateTime without sub-seconds. |
2022-12-24T13:45:23Z | The same dateTime as the previous, expressed as UTC.
|
2022-12-24T05:45:23.856-08:00 | Local dateTime with sub-seconds. |
2022-12-24T13:45:23.856Z | The same dateTime as the previous, expressed as UTC.
|
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumeration of ISO time features. -
Field Summary
Modifier and TypeFieldDescriptionstatic final EnumSet
<ISODateTime.DatePatterns> Fordecode(String, EnumSet<DatePatterns>)
only: accept all valid forms.static final EnumSet
<ISODateTime.DatePatterns> static final EnumSet
<ISODateTime.DatePatterns> -
Method Summary
Modifier and TypeMethodDescriptionstatic GregorianCalendar
decode
(String dateTime, EnumSet<ISODateTime.DatePatterns> constraints) Decodes an ISO compliantdateTime
string.static String
encode
(GregorianCalendar dateTime, EnumSet<ISODateTime.DatePatterns> format) Encodes an ISO compliantdateTime
string.
-
Field Details
-
UTC_NO_SUBSECONDS
-
LOCAL_NO_SUBSECONDS
-
COMPLETE
Fordecode(String, EnumSet<DatePatterns>)
only: accept all valid forms.
-
-
Method Details
-
decode
public static GregorianCalendar decode(String dateTime, EnumSet<ISODateTime.DatePatterns> constraints) Decodes an ISO compliantdateTime
string.- Parameters:
dateTime
- ISO formatteddateTime
stringconstraints
- Permitted input format variants- Returns:
- GregorianCalendar
- Throws:
IllegalArgumentException
-
encode
Encodes an ISO compliantdateTime
string.If
ISODateTime.DatePatterns.MILLISECONDS
is defined, milliseconds (.nnn
] are included in the output, else only seconds are used.If
ISODateTime.DatePatterns.UTC
is defined, UTC format is applied, else local time format is assumed.- Parameters:
dateTime
- The date/time objectformat
- Output format- Returns:
- ISO formatted
dateTime
string
-