Package slash.common.type
Class ISO8601
java.lang.Object
slash.common.type.ISO8601
The
ISO8601 utility class provides helper methods
to deal with date/time formatting using a specific ISO8601-compliant
format (see ISO 8601).
The currently supported format is:
+-YYYY-MM-DDThh:mm:ss[.SSS]TZDwhere:
+-YYYY = four-digit year with optional sign where values ;lteq; 0 are
denoting years BCE and values > 0 are denoting years CE,
e.g. -0001 denotes the year 2 BCE, 0000 denotes the year 1 BCE,
0001 denotes the year 1 CE, and so on...
MM = two-digit month (01=January, etc.)
DD = two-digit day of month (01 through 31)
hh = two digits of hour (00 through 23) (am/pm NOT allowed)
mm = two digits of minute (00 through 59)
ss = two digits of second (00 through 59)
SSS = optionally: three digits of milliseconds (000 through 999)
TZD = time zone designator (Z or +hh:mm or -hh:mm)
Formatting is locale-independent and thread-safe: the numeric fields are rendered with
String.format(java.lang.String, java.lang.Object...) pinned to Locale.ROOT and the zone offset comes from
ZoneOffset, so no shared mutable formatter is involved. An earlier version
used static DecimalFormat instances, which are neither.- Author:
- Unknown
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatDate(Calendar calendar, boolean includeMilliseconds) Formats aCalendarvalue into an ISO8601-compliant date/time string.static StringformatDate(CompactCalendar calendar) Formats aCompactCalendarvalue into an ISO8601-compliant date/time string.static CalendarParses an ISO8601-compliant date/time string.
-
Constructor Details
-
ISO8601
public ISO8601()
-
-
Method Details
-
parseDate
Parses an ISO8601-compliant date/time string.- Parameters:
text- the date/time string to be parsed- Returns:
- a
Calendar, ornullif the input could not be parsed
-
formatDate
Formats aCompactCalendarvalue into an ISO8601-compliant date/time string.- Parameters:
calendar- the time value to be formatted into a date/time string- Returns:
- the formatted date/time string
- Throws:
IllegalArgumentException- if anullargument is passed
-
formatDate
Formats aCalendarvalue into an ISO8601-compliant date/time string.- Parameters:
calendar- the time value to be formatted into a date/time stringincludeMilliseconds- if milli seconds should be included although the spec does not include them- Returns:
- the formatted date/time string
- Throws:
IllegalArgumentException- if anullargument is passed
-