Top Description Fields Constructors Methods
com.fasterxml.jackson.databind.util

public Class ISO8601Utils

extends Object
Class Inheritance
Annotations
@Deprecated
Imports
java.text.ParseException, .ParsePosition, java.util.*

Deprecated

Utilities methods for manipulating dates in iso8601 format. This is much much faster and GC friendly than using SimpleDateFormat so highly suitable if you (un)serialize lots of date objects. Supported parse format: [yyyy-MM-dd|yyyyMMdd][T(hh:mm[:ss[.sss]]|hhmm[ss[.sss]])]?[Z|[+-]hh[:]mm]]
See Also
this specification

Field Summary

Modifier and TypeField and Description
protected static final int
private static final TimeZone
TIMEZONE_Z

Timezone we use for 'Z' in ISO-8601 date/time values: since 2.7 TIMEZONE_UTC; with earlier versions up to 2.7 was TIMEZONE_GMT.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static boolean

Returns:

true if the expected character exist at the given offset
checkOffset
(String
the string to check at the specified offset
value
,
int
the offset to look for the expected character
offset
,
char
the expected character
expected
)

Check if the expected character exist at the given offset in the value.

public static String

Returns:

the date formatted as 'yyyy-MM-ddThh:mm:ssZ'
format
(Date
the date to format
date
)

Format a date into 'yyyy-MM-ddThh:mm:ssZ' (default timezone, no milliseconds precision)

public static String

Returns:

the date formatted as 'yyyy-MM-ddThh:mm:ss[.sss]Z'
format
(Date
the date to format
date
,
boolean
true to include millis precision otherwise false
millis
)

Format a date into 'yyyy-MM-ddThh:mm:ss[.sss]Z' (GMT timezone)

public static String
format(Date date, boolean millis, TimeZone tz)
Deprecated

public static String

Returns:

the date formatted as yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm]
format
(Date
the date to format
date
,
boolean
true to include millis precision otherwise false
millis
,
TimeZone
timezone to use for the formatting (UTC will produce 'Z')
tz
,
Locale loc)

Format date into yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm]

private static int
indexOfNonDigit(String string, int offset)

Returns the index of the first character in the string that is not a digit, starting at offset.

public static Date

Returns:

the parsed date
parse
(String
ISO string to parse in the appropriate format.
date
,
ParsePosition
The position to start parsing from, updated to where parsing stopped.
pos
)

Parse a date from ISO-8601 formatted string.

private static int

Returns:

the int
parseInt
(String
the string to parse
value
,
int
the start index for the integer in the string
beginIndex
,
int
the end index for the integer in the string
endIndex
)

Parse an integer located between 2 given offsets in a string

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEF_8601_LENback to summary
protected static final int DEF_8601_LEN
TIMEZONE_Zback to summary
private static final TimeZone TIMEZONE_Z

Timezone we use for 'Z' in ISO-8601 date/time values: since 2.7 TIMEZONE_UTC; with earlier versions up to 2.7 was TIMEZONE_GMT.

Constructor Detail

ISO8601Utilsback to summary
public ISO8601Utils()

Method Detail

checkOffsetback to summary
private static boolean checkOffset(String value, int offset, char expected)

Check if the expected character exist at the given offset in the value.

Parameters
value:String

the string to check at the specified offset

offset:int

the offset to look for the expected character

expected:char

the expected character

Returns:boolean

true if the expected character exist at the given offset

formatback to summary
public static String format(Date date)

Format a date into 'yyyy-MM-ddThh:mm:ssZ' (default timezone, no milliseconds precision)

Parameters
date:Date

the date to format

Returns:String

the date formatted as 'yyyy-MM-ddThh:mm:ssZ'

formatback to summary
public static String format(Date date, boolean millis)

Format a date into 'yyyy-MM-ddThh:mm:ss[.sss]Z' (GMT timezone)

Parameters
date:Date

the date to format

millis:boolean

true to include millis precision otherwise false

Returns:String

the date formatted as 'yyyy-MM-ddThh:mm:ss[.sss]Z'

formatback to summary
public static String format(Date date, boolean millis, TimeZone tz)

Deprecated

Annotations
@Deprecated
formatback to summary
public static String format(Date date, boolean millis, TimeZone tz, Locale loc)

Format date into yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm]

Parameters
date:Date

the date to format

millis:boolean

true to include millis precision otherwise false

tz:TimeZone

timezone to use for the formatting (UTC will produce 'Z')

Returns:String

the date formatted as yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm]

Since
2.9
indexOfNonDigitback to summary
private static int indexOfNonDigit(String string, int offset)

Returns the index of the first character in the string that is not a digit, starting at offset.

parseback to summary
public static Date parse(String date, ParsePosition pos) throws ParseException

Parse a date from ISO-8601 formatted string. It expects a format [yyyy-MM-dd|yyyyMMdd][T(hh:mm[:ss[.sss]]|hhmm[ss[.sss]])]?[Z|[+-]hh:mm]]

Parameters
date:String

ISO string to parse in the appropriate format.

pos:ParsePosition

The position to start parsing from, updated to where parsing stopped.

Returns:Date

the parsed date

Exceptions
ParseException:
if the date is not in the appropriate format
parseIntback to summary
private static int parseInt(String value, int beginIndex, int endIndex) throws NumberFormatException

Parse an integer located between 2 given offsets in a string

Parameters
value:String

the string to parse

beginIndex:int

the start index for the integer in the string

endIndex:int

the end index for the integer in the string

Returns:int

the int

Exceptions
NumberFormatException:
if the value is not a number